将数据插入ios中的表视图的问题

时间:2012-03-01 05:42:59

标签: ios ios5 uitableview

我开发了一个应用程序,我从核心数据中获取数据,并在表格视图中显示它。我得到了一切,直到获取数据,但在将它们插入表视图时,只有最后一个条目显示在表视图中。以下是我编写的代码,请预览并帮助我获得解决方案。

 Deviceinfo *app = [arr objectAtIndex:indexPath.row];
switch(indexPath.row)
{


case 0:  
        NSLog(@"%@",app.platform);
        cell.textLabel.text = @"platform";
        cell.detailTextLabel.text =[app platform];

case 1:
        NSLog(@"%@",app.model);
        cell.textLabel.text = @"model";
        cell.detailTextLabel.text = [app model];
case 2:
        NSLog(@"%@",app.mac_address);
        cell.textLabel.text = @"mac address";
        cell.detailTextLabel.text = [app mac_address]; 
}
return cell;

我在cellForRowAtIndexpath委托中实现此代码。我只在表视图中获取mac地址。希望有更好的解决方案

由于

1 个答案:

答案 0 :(得分:1)

在每个案例之后插入break语句,否则案例将会落到下一个案例

switch(x) {
    case 1:
        break;
    default:
        break;
}

根据您的其他评论,尝试以下内容:每个设备都有自己的表格视图部分,每个部分将有3个表格视图行,每个信息对应一条信息。

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return devices.count
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{        
    static NSString *CellIdentifier = @"Cell";

    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (!cell) {
        cell = [[FEMenuItemInfoCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];            
    }    

    Device *device = [devices objectAtIndex:indexPath.section];

    switch (indexPath.row) {
        case 0:
            cell.textLabel.text = @"platform";
            cell.detailTextLabel.text = [device platform]; 
            break;            
        case 1:
            cell.textLabel.text = @"model";
            cell.detailTextLabel.text = [device mac_address]; 
            break;
        case 2:
            cell.textLabel.text = @"mac address";
            cell.detailTextLabel.text = [device mac_address]; 
            break;                        
    }

    return cell;
}