Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone Can';t将单元格添加到UITableView,从模式VC添加到表VC(复杂)_Iphone_Ios_Objective C_Tableview_Modalviewcontroller - Fatal编程技术网

Iphone Can';t将单元格添加到UITableView,从模式VC添加到表VC(复杂)

Iphone Can';t将单元格添加到UITableView,从模式VC添加到表VC(复杂),iphone,ios,objective-c,tableview,modalviewcontroller,Iphone,Ios,Objective C,Tableview,Modalviewcontroller,我正在尝试从模式视图控制器向表视图控制器添加单元格。我的数据源数组有多个属性(名称、时间间隔)。现在,我的模态视图控制器中有一个委托/协议,它将数据发送到表视图控制器。但是,由于某些原因,我可以将数据添加到数组中,但无法使用该数据将单元格添加到tableview中。这是我的密码: ToToToTableViewController.h(TableViewController) Properties2ViewController.h(ModalViewController) 下面是任务类的属性…如

我正在尝试从模式视图控制器向表视图控制器添加单元格。我的数据源数组有多个属性(名称、时间间隔)。现在,我的模态视图控制器中有一个委托/协议,它将数据发送到表视图控制器。但是,由于某些原因,我可以将数据添加到数组中,但无法使用该数据将单元格添加到tableview中。这是我的密码:

ToToToTableViewController.h(TableViewController)

Properties2ViewController.h(ModalViewController)

下面是任务类的属性…如果有帮助的话

@interface Tasks : NSObject
@property (strong, nonatomic) NSString *taskName;
@property NSTimeInterval timeInterval;
@property NSDate *dateCreated;

-(id)initWith:(NSString *)tskNme :(NSTimeInterval)timeInt :(NSDate *)dateCreat;
@end
---编辑----- 因此,我尝试将其放入Properties2ViewControllerdIdentiterPropertiesSuccessfully委托方法中,但仍没有创建单元格…:

-(void)properties2ViewControllerDidEnterPropertiesSuccesfully:(Tasks *)t{
    [taskArray addObject:t];
    [self.tableView reloadData];
    int lastRow = [[self tableView] numberOfRowsInSection:0];
    NSIndexPath *ip = [NSIndexPath indexPathForItem:lastRow inSection:0];
    [self.tableView cellForRowAtIndexPath:ip];
}
还有,如果我换了

[self.tableView cellForRowAtIndexPath:ip];


然后抛出一个异常(由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因是:“尝试将行0插入节0,但更新后节0中只有0行”)

您可能希望在中尝试[tableView reloadData]

- properties2ViewControllerDidEnterPropertiesSuccesfully

最后出现的错误表明该条目从未进入数组。在调用[taskArray addObject:t];之后,是否可以检查数组的长度?另外,检查对象(t)的值,并查看是否实际传入了正确的testTask

看起来您实际上并没有创建taskArray,只是声明了它。尝试在ToToToTableViewControllers viewDidLoad中添加此项

taskArray = [[NSMutableArray alloc] init];

我只是尝试了一下,但不幸的是它没有添加任何单元格:(在Properties2ViewControllerdIdentiterPropertiesSuccessfully调用[tableView重载数据]之后,tableView:CellForRowatineIndexPath被调用了吗?我不相信。indexpath是什么?我只是尝试了以下方法:'-(void)Properties2ViewControllerdIdentiterPropertiesSuccessfully:(Tasks*){[taskArray addObject:t];[self.tableView重载数据];int lastRow=[[self tableView]节中的行数:0];NSIndexPath*ip=[NSIndexPath indexPathForItem:lastRow分区:0];[self.tableView cellForRowAtIndexPath:ip];]好吧,这个评论搞乱了格式,所以我用我所做的编辑了主帖子你的Properties 2ViewController.h与你的ToToToTableViewController.h相同。也许发布Properties 2ViewController的正确代码,这样我们就可以检查它了?天哪,我怎么没注意到……修复了嗯……你是对的。我在添加了t之后检查了taskArray对象,计数仍然为0。但是,taskName值和timeInterval值已成功传递。@user2533646我根据您的反馈添加了一个可能的解决方案。是的!!您太棒了。我太高兴了!!!!!非常感谢您,我已经为此工作了8个小时!!!
-(void)properties2ViewControllerDidEnterPropertiesSuccesfully:(Tasks *)t{
    [taskArray addObject:t];
    [self.tableView reloadData];
    int lastRow = [[self tableView] numberOfRowsInSection:0];
    NSIndexPath *ip = [NSIndexPath indexPathForItem:lastRow inSection:0];
    [self.tableView cellForRowAtIndexPath:ip];
}
[self.tableView cellForRowAtIndexPath:ip];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:ip] withRowAnimation:UITableViewRowAnimationTop];
- properties2ViewControllerDidEnterPropertiesSuccesfully
taskArray = [[NSMutableArray alloc] init];