这是我要尝试的操作,我将“视图”设置为一个“图像”和“ 3个标签”,每个都是相同的。
[viewarray addObject:xView]; //view array is NSMutable Array and I am adding 5-6 views
[tblView insertRowsAtIndexPaths:viewarray withRowAnimation:UITableViewRowAnimationFade];
这段代码没有给出任何错误,但是也没有在表中添加任何内容。
我做错了,如果可能,还请给我代码片段,以创建
Custom UIView
,其中One UIImageView
+ 3个标签左侧图像和右侧3个标签 最佳答案
UITableView不要将UIViews用作单元格。它实际上使用了UITableViewCell。
方法insertRowsAtIndexPaths:withRowAnimations:
需要一个NSIndexPath的NSArray。
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的更多信息:
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewCell_Class/Reference/Reference.html#//apple_ref/occ/cl/UITableViewCell
或者,您可以在此处查看《 Table View编程指南》:
https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/TableView_iPhone/AboutTableViewsiPhone/AboutTableViewsiPhone.html#//apple_ref/doc/uid/TP40007451-CH1-SW1
关于iphone - 在包含 View 集的TableView中添加NSMutableArray,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4563278/