2012-03-20 7 views
0

私のアプリではテーブルビューから行を削除できません。テーブルビューの内容は、Web(GET)レスポンスとして提供され、テーブルビューに表示されます。2番目のビューコントローラにその詳細を表示します(インデックスで行をクリックするとプッシュします)。 (..メッセージ、日付など)テーブルビューから行を削除できません

sharedDa= (BNT_AppDelegate *)([[UIApplication sharedApplication]delegate]); 
    mm= [[sharedDa messagesDict]objectForKey:@"message"];//mm is NSDictionary 

mmは、いくつかのプロパティが含まれています(のviewDidLoadで)と私は辞書からインデックスでオブジェクトを削除する必要があると思う: ここに私のコードの一部です。どのように私はこの状況に対処できますか?

EDIT-2: ここにJSONオブジェクトがあります。

{ 
    button = 30; 
    message =  (
       { 
      date = "2012-03-21 20:13:10"; 
      message = "message 1"; 
     }, 
       { 
      date = "2012-03-21 20:13:42"; 
      message = "asdf nkop jp?l?f"; 
     }, 
       { 
      date = "2012-03-22 10:06:11"; 
      message = "test local notification message"; 
     }, 
       { 
      date = "2012-03-22 10:06:41"; 
      message = "second test of uilocalnotification"; 
     }, 
       { 
      date = "2012-03-22 10:08:13"; 
      message = "third test of notification"; 
     } 
    ); 
} 

そして、ここでは私の初期化コードです:

sharedDa= (BNT_AppDelegate *)([[UIApplication sharedApplication]delegate]); 
//mm is mutableDictionary and the others are mutable array 
     mm= [[sharedDa messagesDict]objectForKey:@"message"]; 
     // NSLog(@"JSON message: %@", [sharedDa messagesDict]); 
     buttonVersion= [sharedDa.messagesDict objectForKey:@"button"]; 
     mySecondArray= [mm valueForKey:@"date"]; 
     myIDsArray=[mm valueForKey:@"ID"]; 

私は可変辞書を解析され、それと異なる可変配列を初期化し、ここで行を削除するには丁度私のデリゲートメソッドです。

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (editingStyle == UITableViewCellEditingStyleDelete) { 
     // Delete the row from the data source 


     NSLog(@"Thread: %@", [NSThread currentThread]); 

     [self.myIDsArray removeObjectAtIndex:indexPath.row]; 
     [self.myArray removeObjectAtIndex:indexPath.row]; 
     [self.mySecondArray removeObjectAtIndex:indexPath.row]; 
     [self.buttonVersion removeObjectAtIndex:indexPath.row]; 
     // 
     [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; } } 

マイアプリがクラッシュし、コンソールに私は、これらの3つの行を取得:

Thread: <NSThread: 0x75719d0>{name = (null), num = 1} 
[Switching to process 1472 thread 0x10a03] 
(gdb) 

を私はそれが非常に長い質問になりました知っているが、誰も私にアイデアを与えることができますか?

答えて

1

まず、変数に少し読みやすい名前を付けてください。mmは少しばかに見えます。

はのは、これらのオブジェクトを保持し、

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{} 

の実装では、あなたのすべてのアレイのための方法removeObjectAtIndex:を使用するために、3つの異なるNSMutableArray Sを作成し、あなたの辞書に三つの異なるオブジェクトがあるとしましょう。

関連する問題