这是我正在尝试做的,我已经设置了一个图像和3个标签的视图,每个都是相同的。
[viewarray addObject:xView]; //view array is NSMutable Array and I am adding 5-6 views
[tblView insertRowsAtIndexPaths:viewarray withRowAnimation:UITableViewRowAnimationFade];这段代码没有给出任何错误,但它也没有在表中添加任何内容。
我做错了什么,如果可能的话,请给我代码片段来创建带有One UIImageView+ 3标签左侧图像和右侧3标签的Custom UIView
发布于 2013-12-11 03:44:57
UITableView不使用UIViews作为单元格。它实际上使用的是UITableViewCell。方法insertRowsAtIndexPaths:withRowAnimations:需要NSArray为NSIndexPath。
UITableView中的每个UITableViewCell对应一个NSIndexPath。NSIndexPath保存UITableView中特定UITableViewCell的顺序和节号。
例如:NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:1];这将为区域1上的第0行(第一个单元格)创建一个NSIndexPath。
在创建NSIndexPath之后,您可以使用insertRowsAtIndexPaths:withRowAnimations:。
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
这将使UITableView调用cellForRowAtIndexPath:来使用您放入NSIndexPath中的信息创建一个新的单元格。
你可以在这里获得更多关于UITableViewCell的信息:
或者,您可以在此处查看表视图编程指南:
发布于 2010-12-30 23:41:22
您需要查看UITableView和UITableViewCell信息。
表格视图使用UITableViewCell对象来显示单元格。
insertRowsAtIndexPaths方法只是通知UITableView需要添加一些单元格。
这是tableView:cellForRowAtIndexPath:方法( UITableViewDataSource协议),用于设置表格的单元格。
发布于 2013-05-31 02:00:11
insertRowsAtIndexPaths:withRowAnimations:实际上希望第一个参数是索引路径数组,而不是视图。
所以正确的用法应该是:
[tblView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:3 inSection:4]] withRowAnimations:UITableViewRowAnimationAutomatic];在这种情况下,表视图将通过调用- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath自动要求其数据源为这些索引路径提供实际的单元格视图
https://stackoverflow.com/questions/4563278
复制相似问题