2012-03-01 44 views
0

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

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

插入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; 
} 
+0

但我需要所有这三种情况下执行。如果我插入中断后执行第一个案件控制退出循环权利如何执行其余案件 – NNR 2012-03-01 08:04:34

+0

我需要所有案件应执行并显示其内容在不同的单元格。 – NNR 2012-03-01 08:34:31

+0

您需要在多行上使用多个单元格。等一下,我会用适当的代码更新它。 – richerd 2012-03-02 03:21:20