动态tableview单元格创建

时间:2012-10-26 11:06:41

标签: objective-c ios uitableview

我必须在其中制作包含不同单元格的tableview。我有三个偏好,表格取决于它们。可能有6个不同的表格视图 - 1个单元格,1个单元格和3个单元格,没有单元格,2个单元格和3个单元格等等,这取决于首选项

这是最好的方法吗?

也许有人知道很好的例子,或者教这个

2 个答案:

答案 0 :(得分:1)

您只能使用不同的部分制作一个UITableView

根据您的部分ID,您可能会在

中返回不同的单元格
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

indexPath包含row& section值。

此外,您可能会在一个部分中返回不同数量的行:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

答案 1 :(得分:1)

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{
//pass value to numper of cells;
return 4 (or) 2;
}

//use this to add cell 
[tableview reloadData];
相关问题