2012-03-01 14 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
は、よりよい解決策を

期待して挿入し、次のような何かをしようと、そうでない場合は、ちょうどあなたの追加のコメントに基づいて、次のいずれか

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

にかかわらず、落ちる、各ケースの後のステートメントを破ります:各デバイスには独自のテーブルビューセクションがあり、各セクションには3つのテーブルビュー行があり、各情報に1つずつあります。

- (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

しかし、私は3つすべての場合が実行される必要があります。最初のケースコントロールを実行した後にブレークを挿入すると、残りのケースがどのように実行されるのかループが終了します。 – NNR

+0

すべてのケースが実行され、その内容が別のセルに表示される必要があります。 – NNR

+0

複数の行に複数のセルを使用する必要があります。私はあなたのケースのための適切なコードでそれを更新するつもりです。 – richerd