好的,我有一些复杂的数据需要放在自定义表视图中。下面是结构NSMutableDictionary
cellData = [ "Section Header title" : NSMutableArray]; // NSMutableArray has custom cell objects
因此,基本上,我正在用自定义单元格对象的相应节标题名称标记数组。问题是,我无法将数据设置为表格视图单元格。到目前为止,我一直在...cellForRowAtIndexPath
HomeTableViewCell *cell = (HomeTableViewCell*) [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
NSString *sectionTitle = [sectionNames objectAtIndex:indexPath.row];
NSMutableArray *array = [cellData objectForKey:sectionTitle];
if ([sectionTitle isEqual:@"Email"]) {
Email *email = (Email*) [arr objectAtindex:indexPath.row]; // I know this is wrong because there're multiple objects in "array". I couldn't get it right
[cell setCellData:...];
}
仅仅通过使用indexPath.row
我无法从“数组”中获取所有对象。是否有人尝试使用字典值(例如““ key”:“ Array”)填充自定义表格视图单元格?
我认为您想要做的是在获取节标题时使用indexPath.section:
NSString *sectionTitle = [sectionNames objectAtIndex:indexPath.section];
拥有正确的部分后,您的数据应正确排列。
当然,这假设您已正确设置了其他方法,即:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return sectionNames.count;
}
和
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSString *sectionTitle = [sectionNames objectAtIndex:indexPath.row];
NSMutableArray *array = [cellData objectForKey:sectionTitle];
return array.count;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句