Uitableview与两个不同的模型类相同的uitableview单元格

时间:2013-11-08 07:21:38

标签: ios iphone objective-c

我有一个uitableview控制器类,我使用单个UITableViewCell,但我使用两个不同的模型类。在我的tableview中,我必须使用这两个模型类显示从数据库中获取的值。对于一个模型类,我可以获取数据并显示它。但是我无法显示第二个模型类的数据。  有人帮我解决问题

1 个答案:

答案 0 :(得分:0)

查看我的代码示例,管理2种类型的单元格(收件箱或发件箱),希望它能为您提供帮助。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
        Feedback *feedback =     [self.guideline.feedbacks objectAtIndex:indexPath.row];
        if([feedback.user_role isEqualToString:@"STORE"] || !feedback.user_role){
            ChatInboxCelliPad* icell = [tableView dequeueReusableCellWithIdentifier:@"ChatInboxCell"];
            if(!icell){
                icell = [[ChatInboxCelliPad alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ChatInboxCell"];
            }
            [icell setData:feedback];
            return icell;

        }
        else{
            ChatOutboxCell* ocell = [tableView dequeueReusableCellWithIdentifier:@"ChatOutboxCell"];

            if(!ocell){
                ocell = [[ChatOutboxCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ChatOutboxCell"];
            }
            [ocell setData:feedback];
            return ocell;

        }
}