editingStyleForRowAtIndexPathは呼ば取得されていません(だから、削除ボタンが現れてされます)
-
19-09-2019 - |
質問
私は移動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
コンパイル時に警告なしています。
ありがとうございます。
解決
タグ正しくメソッド名を大文字にしてください
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
これは大文字S
にeditingStyleForRowAtIndexPath
であります。 ObjCセレクタは、大文字と小文字が区別されます。テーブルビューは、それのデリゲートは、あなたが戻り値を提供しようとしているメソッドに応答とは思いません。
他のヒント
あなたが編集モードでNOに複数の選択を設定する必要があります。
self.tableview.allowsMultipleSelectionDuringEditing = NO;
もう一つの理由は、あなたにも実装する必要があるということかもしれません。
- (void)tableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
コントロールは、それのデリゲートアウトレットは、ファイルの所有者に接続されていない場合は呼び出されていないeditingStyleForRowAtIndexPath(および他の代表者)のためのもう一つの理由がある。
はい、これは明白ですが、それは簡単に見過ごさいます。
所属していません StackOverflow