2016-07-28 9 views
0

これは、tableviewcellの行を削除するためのコードです。UITableviewcell NSMutableArray配列データの代わりに辞書キーを使用して削除ボタンを表示

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     if (editingStyle == UITableViewCellEditingStyleDelete) { 
      [Keys removeObjectAtIndex:indexPath.row]; // this line error 
      [_tableView deleteRowsAtIndexPaths:[NSMutableArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
     } 
} 

エラー行は `[Key removeObjectAtIndex:indexPath.row]; ' 。

私はこのコードがNSMutableArrayで使用されるべきであることを知っていますが、私はこのセルを削除するためのPlistのDictionary Keysに同じ方法を使用します。

編集可能:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    static NSString *CellIdentifier = @"Cell"; 
    CustomeCell *Customecell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (Customecell == nil){ 
     Customecell =[[CustomeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 
    Customecell.nameLbl.text = [Keys objectAtIndex:indexPath.row]; 
    Customecell.Img.image = [UIImage imageNamed:[[content valueForKey:[Keys objectAtIndex:indexPath.row]] valueForKey:@"image"]]; 
    Customecell.statusLabel.text = [[content valueForKey:[Keys objectAtIndex:indexPath.row]] valueForKey:@"status"]; 
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"]; 

    // NSString *dateString = [dateFormatter stringFromDate:[NSDate date]]; // current date 
    NSString *dateString = [dateFormatter stringFromDate:[[content valueForKey:[Keys objectAtIndex:indexPath.row]] valueForKey:@"date"]]; 
    NSLog(@"date: %@", dateString); 
    Customecell.dateLbl.text=dateString; 
    return Customecell; 
+0

をしてください試してみてください。 –

+0

'tableView:cellForRowAtIndexPath:'のコードは何ですか? NSDictionaryオブジェクトがモデルデータソースとしてどのように機能するのかわからない場合、私たちはあなたを助けることはできません。 – Larme

+0

エラーは次のとおりです。 'NSArray'の表示されない@interfaceによってセレクタ 'removeObjectAtIndex:'が宣言されます –

答えて

0

は、いずれかの答えは、私が知っている知っているこのコード

 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
     { 
      if (editingStyle == UITableViewCellEditingStyleDelete) { 
       [_tableView deleteRowsAtIndexPaths:[Keys objectAtIndex:indexPath.row] withRowAnimation:UITableViewRowAnimationFade]; 
       [Keys removeObjectAtIndex:indexPath.row]; // this line error 
      } 
    } 
+0

同じエラーがPinkeshを反映しています –

関連する問題