2017-10-27 9 views
1

サービスを呼び出すときにName、Country、Idの下に次のレスポンスでテーブルビューを読み込みました。ロード後、Objective-Cで他のサービスを呼び出すことで、tableviewセルのテキストの値を変更します。

(
{ 
    Name = David; 
    Country = USA 
    Id = 100; 
}, 
{ 
    Name = Mike; 
    Id = 101; 
    Country = Australia 
}, 
{ 
    Name = John; 
    Id = 102; 
    Country = UK 
} 
) 

私はtabview footerにボタンがあります。ボタンが押されたときに、テーブルビュー内の名前だけを交換するサービスを呼び出すが、国とIDは入れ替えないと、ボタンを押したときのレスポンスは以下のようになります。

(
{ 
    Name = Phillip; 
    Id = 200; 
}, 
{ 
    Name = Jackman; 
    Id = 201; 
}, 
{ 
    Name = Arrow; 
    Id = 202; 
} 
) 

以下は私が試みたものです。しかし

- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    static NSString *CellIdentifier = @"Cell"; 
    CartItemCell *cell = (CartItemCell *) [aTableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) { 

     NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CartItemCell" owner:self options:nil]; 

     for (id currentObject in topLevelObjects){ 
      if ([currentObject isKindOfClass:[UITableViewCell class]]){ 
       cell = (CartItemCell *) currentObject; 

       cell.backgroundColor=[UIColor clearColor]; 
      } 
     } 

    } 

    NSMutableDictionary *detailsdict=[cartArray objectAtIndex:indexPath.row]; 

    cell.lblName.text = [detailsdict objectForKey:@"Name"]; 
    cell.lblCountry.text = [detailsdict objectForKey:@"Country"]; 
    cell.lblId.text = [detailsdict objectForKey:@"Id"]; 
cell.selectionStyle=UITableViewCellSelectionStyleNone; 
return cell; 

} 

名前を交換することはできませんあなたはボタンが押された時には、次のコードを使用して、私はthis.TIA

+0

さらに詳しい情報をご提供ください。 –

+0

あなたは何を試しましたか? – Himanth

答えて

0

を解決するために助けてもらえますが、新しいデータを取得し、

arrUserListこの配列内のすべてのデータをassine
NSMutableArray *arrUserList = [[NSMutableArray alloc]init]; 

for (int i=0; i<[arrUserList count]; i++) 
{ 

    NSString *strUserName = [[arrUserList objectAtIndex:i] valueForKey:@"Name"]; 
    for (int j=0; j<[cartArray count]; j++) 
    { 
     if (i==j) { 
      [[cartArray objectAtIndex:j] setValue:strUserName forKey:@"Name"]; 
     } 

    } 
} 
+1

ありがとう@Navneet Baldha。 Worksパーフェクト – Rajeev

+0

大丈夫! @Rajeev他のヘルプが必要なときにお知らせください:)。 –

0

ディクショナリの値をディクショナリの配列から直接更新することはできません。だから私たちは、すべての更新された値を保持し、それを同じインデックスで古いものと置き換える一時的な辞書を作り出すことができます。そして、最後にリロードテーブルのデータ。

for (int newIndex = 0 ; newIndex < arrNewUserList.count ; newIndex++) { 
    for (int oldIndex = 0 ; oldIndex < arrUserList.count ; oldIndex++) { 
     if(arrNewUserList[newIndex]["Id"] == arrUserList[oldIndex]["Id"]) { 
      NSMutableDictionary *dict = [NSMutableDictionary alloc] init]; 
      dict = arrUserList[oldIndex]; 
      dict["name"] = arrNewUserList[newIndex]["name"];   
      [arrUserList replaceObjectAtIndex:oldIndex withObject:dict]; 
      break; 
     } 
    } 
} 

[tableview reloadData]; 
関連する問題