我運行這個功能:不能運行在Objective-C函數
- (void)insertRows {
[_objects insertObject:[NSDate date] atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
,它必須運行此功能
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
NSDate *object = _objects[indexPath.row];
cell.textLabel.text = [object description];
return cell;
}
,但此功能無法運行......請幫助如何運行的tableView ...功能
- (IBAction)insertObject {
[[MasterViewController alloc] insertRows];
}
- 此代碼運行insertRows,我用的斷點
檢查此- (IBAction)insertObject:(id)sender {
[_objects insertObject:[NSDate date] atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
NSLog(@"log:insert-indexPath: %i",indexPath.row);
NSDate *object = _objects[indexPath.row];
NSLog(@"log:insert-object %@",object.description);
}
-works與它,爲什麼?
可以'self.tableview'爲零? – Chuck
Chuck,no ...因爲如果我通過IBAction(tap button)運行insertRow ... tableview ...作品... – EarthUser
因此可能你沒有調用該方法。 –