3

私はuitableviewcellsを動かして遊んでいます、そしてどんな理由であれ、

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
           editingstyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleNone; //<-- bp set on it
}

が呼び出されていません(ブレークポイントを設定しました)-したがって、テーブルには削除オプションが表示されていますが、それは望ましくありません。これが私の実装です:

@implementation MoveItController
@synthesize mList;

- (IBAction)moveButton
{
    [self.tableView setEditing:!self.tableView.editing animated:YES];

    [self.navigationItem.rightBarButtonItem setTitle:(self.tableView.editing)? @"Done" : @"Move"];
}

- (void)viewDidLoad
{
    if (mList == nil)
    {
        mList = [[NSMutableArray alloc] initWithObjects:@"$1", @"$2", @"$5", @"$10", @"$20", @"$50", @"$100", nil];
    }

    UIBarButtonItem *mvButton = [[UIBarButtonItem alloc]
                                 initWithTitle:@"Move" 
                                 style:UIBarButtonItemStyleBordered 
                                 target:self 
                                 action:@selector(moveButton)];
    self.navigationItem.rightBarButtonItem = mvButton;
    [mvButton release];
    [super viewDidLoad];
}

// Table datasource methods

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [mList count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *moveItCellId = @"moveItCellId";


    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:moveItCellId];
    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:moveItCellId] autorelease];
        cell.showsReorderControl = YES;
    }

    cell.textLabel.text = [mList objectAtIndex:[indexPath row]];
    return cell;
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
           editingstyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleNone;
}

- (BOOL)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath
toIndexPath:(NSIndexPath *)toIndexPath
{
    id object = [[mList objectAtIndex:[fromIndexPath row]] retain];
    [mList removeObjectAtIndex:[fromIndexPath row]];
    [mList insertObject:object atIndex:[toIndexPath row]];
    [object release];                 
}

- (void) dealloc
{
    [mList release];
    [super dealloc];
}

@end

コンパイル時に警告はありません。

ありがとう!

4

4 に答える 4

6

編集モードで複数選択を NO に設定する必要があります

self.tableview.allowsMultipleSelectionDuringEditing = NO;
于 2014-12-25T13:54:44.593 に答える
2

メソッド名を適切に大文字にしてみてください

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
           editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

それは大文字のSinです。editingStyleForRowAtIndexPathObjC セレクターは大文字と小文字を区別します。テーブルビューは、戻り値を提供しようとしているメソッドにデリゲートが応答するとは考えていません。

于 2010-02-09T03:21:48.183 に答える
1

もう1つの理由は、実装する必要があることかもしれません

- (void)tableView:(UITableView *)tableView
  commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
  forRowAtIndexPath:(NSIndexPath *)indexPath
于 2015-08-19T08:18:09.343 に答える
0

Another reason for editingStyleForRowAtIndexPath (and other delegates) not being called is if the control does not have it's delegate outlet connected to the File's Owner.

Yes, this is obvious but it's easily overlooked.

于 2013-08-31T01:29:58.733 に答える