我试图将信息显示为带有2个动态单元的分组UITableView
。每个分组的UITableView
需要在单个视图中调用10次;每个分组UITableView
在其两个单元之间显示不同的信息。动态加载分组tableView
现在我试图显示存储在posts
中的数据库中的所有数据。但是,当我运行此版本时,应用程序崩溃。如果我更改返回[self.posts count]
在numberOfSectionsInTableView:
返回1
,我只能加载一个部分,如预测。
我的问题是如何显示10个分组的表格部分,每个部分有不同的信息?
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
//#warning Potentially incomplete method implementation.
// Return the number of sections.
return [self.posts count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSInteger returnValue = 2;
switch (section) {
case 0:
{
returnValue = 2;
break;
}
default:
break;
}
return returnValue;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier1 = @"Cell";
UITableViewCell *cell;
if (indexPath.section==0)
{
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1];
}
if (indexPath.row==0)
{
cell.textLabel.text = [[self.posts objectAtIndex:indexPath.row] objectForKey:@"name"];
}
if (indexPath.row==1)
{
cell.textLabel.text = [[self.posts objectAtIndex:indexPath.row] objectForKey:@"message"];
}
}
return cell;
}
我能够得到正确数量的部分。但是,它们都是相同的。我如何将正确的名称和消息加载到每个部分? – williams 2013-04-24 04:41:46
@williams看到我的upadated代码.. – Mani 2013-04-24 04:55:12
工程就像一个魅力。谢谢! – williams 2013-04-24 05:07:26