0
我想在我的tableview中添加一个对象来动态插入行。在tableview中添加对象
该代码似乎没有工作,没有插入行。
代码:
- (void)viewDidLoad {
[super viewDidLoad];
NSString *newString = @"test!";
[self.greekLetters addObject:newString];
}
- (NSInteger)tableView:(UITableView *) tableView numberOfRowsInSection:(NSInteger)section {
return [self.greekLetters count];
}
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
NSString *SimpleIdentifier = @"SimpleIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleIdentifier];
if (cell == nil) {
cell = ([[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:(SimpleIdentifier)]);
}
cell.textLabel.text = [NSString stringWithFormat:@"%@", [self.greekLetters objectAtIndex:indexPath.row]];
cell.detailTextLabel.text = @"Laatste datum";
return cell;
}
对象不加入到为textLabel文本,它有没有一个新行。我对这类iOS很陌生,所以代码有什么问题?
我尝试了很多东西,但无法让它工作。
谢谢。
'self.greekLetters'它在哪里初始化?它是'零'吗? – Larme
在viewcontroller.h中。 @属性(复制,非原子)NSMutableArray * greekLetters; – Anoniem
你在哪里做'self.greekLetters = [[NSMutableArray alloc] init];'。 – Larme