2

Three20 はすばらしいライブラリです。これにより、テーブルの操作が非常に簡単になります。しかし、私が気付いた 1 つのギャップは、行の削除とアニメーションです。これを行うために何時間も費やしましたが、これが私がやっていることです:

// get current index patch
UITableView* table = [super tableView];
NSIndexPath *indexPath = [table indexPathForSelectedRow];

//delete row in data source
TTListDataSource * source = (TTListDataSource *)self.dataSource;
[source.items removeObjectAtIndex:indexPath.row]; 

// delete row from the table, with animation
[table deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

このコードを実行すると、次のエラーが表示されます: [NSCFArray objectAtIndex:]: index (0) beyond bounds (0)

TTTableViewController から継承したクラスを使用しています。また、できる限り Three20 を使用しているため、DataSourceDelegate や TableViewDelegate は実装していません。だから、これは私がデータソースを作成する方法です:

for(NSDictionary *album in (NSArray *)albums){

TTTableRightImageItem *item = [TTTableRightImageItem itemWithText:@"name"  
            imageURL:@"image url" 
           defaultImage:nil 
          imageStyle:TTSTYLE(rounded)
           URL:@"url of selector where I actually catch the tap on a row"];
[tableItems addObject:item];
}
self.dataSource = [TTListDataSource dataSourceWithItems:tableItems];

この記事 (記事)を読みましたが、役に立ちません :(

ですから、これはこのサイトの達人にとって非常に簡単であることを知っています. これを行う方法の高度なサンプルを教えてください

ありがとう

4

2 に答える 2

4

「EXC_BAD_ACCESS」も入りましmodel:didDeleteObject:atIndexPath:たが、その問題は解決しました。

TTTableViewController で行を削除するには、次のtableView:commitEditingStyle:ように DataSource 実装に実装する必要があります。

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
        forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        id object = [[self.items objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];

        [self.model didDeleteObject:object atIndexPath:indexPath];
    }
}

tableView:willRemoveObject:atIndexPath:また、DataSourceに実装する必要があります。

- (NSIndexPath*) tableView:(UITableView *)tableView willRemoveObject:(id)object atIndexPath:(NSIndexPath *)indexPath {
    // オブジェクトを削除
    [オブジェクトdeleteFromDB];

    // セクションが削除された場合、removeItemAtIndexPath は YES を返します
    if ([self removeItemAtIndexPath:indexPath andSectionIfEmpty:YES]) {
        // そのセクションへのインデックス パスのみを削除します
        [NSIndexPath indexPathWithIndex:indexPath.section] を返します。
    } そうしないと {
        indexPath を返します。
    }
}

NSIndexPathトリックは、空になるセクションのみを含むように返すを変更することです。次に、TTTableViewController のコードは、セルではなくセクションを削除します。

HTH

于 2010-03-08T13:33:41.823 に答える
1

私が最初に見つけたのは、テーブルが編集モードでないときにテーブルから行を削除しているということです。

于 2009-12-06T19:06:32.513 に答える