在我的应用程序中,我有一项要求,例如以以下格式保存itemsArray中的数据,如
iPhone
iPad
iPod Touch
和我试图在UITableView中显示的相同数据
但它仅采用第一项i.e iPhone
它没有显示itemsArray中的其余项目。
我一直在尝试这个,但我无法找到它的解决方案。
任何人都可以帮我解决这个问题。
我是Objective C的新手。
先谢谢。
答案 0 :(得分:1)
如果您想要单个单元格中的所有3个项目,则按如下方式创建一个字典:
NSMutableArray * contentsArray = [NSMutableArray array];
NSMutableDictionary * allContacts = [NSMutableDictionary dictionary];
for(int i = 0; i < yourItemArrayCount; i++) {
[allContacts setObject:[yourItemArray objectAtIndex:i] forKey:@"key %@",[[youtItemArray objectAtIndex:i] stringValue]];
}
[contentsArray addObject:allContacts];
然后按照以下方法
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//Write your dictionary logic here
NSDictionary *dict = [contentsArray objectAtIndex:indexpath.row];
//Necessary logic will go here.
}
在代码中添加以下方法
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 60; //You can set height of cell here.
}
答案 1 :(得分:1)
在表datasource / delegates中调试数据源。您的问题仅适用于3个项目。它可以静态完成,如上面的博客所示。
但是实际调整表视图单元格/行高的大小。你必须使用自动布局。
点击链接: // http://www.raywenderlich.com/73602/dynamic-table-view-cell-height-auto-layout