タブ コントローラーをルート ビュー コントローラーとして使用するタブ ビュー アプリケーションがあります。私が持っているビューの1つは、すべてのセルを編集可能にし、セルを追加できるようにする追加/編集ボタンをクリックして編集できるようにしたいテーブルビューです。
テーブル ビューにナビゲーション バーを追加し、次のコードを使用してバーにボタンを作成しようとしました。このボタンを押すと、すべてのセルが編集可能になります。
- (void)viewDidLoad {
[super viewDidLoad];
UIBarButtonItem *editButton = [[UIBarButtonItem alloc]
initWithTitle:@"Delete"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(toggleEdit:)];
self.navigationItem.rightBarButtonItem = editButton;
}
-(IBAction)toggleEdit:(id)sender {
[self.mTableView setEditing:!self.mTableView.editing animated:YES];
if (self.mTableView.editing)
[self.navigationItem.rightBarButtonItem setTitle:@"Done"];
else
[self.navigationItem.rightBarButtonItem setTitle:@"Delete"];
}
コードが機能せず、ナビゲーション バーにボタンが生成されません。ナビゲーション コントローラーを使用する必要があることを読みましたが、この 1 つのページ (タブ ビュー アプリで) を使用する場合、タブ バーが選択オプションとしてナビゲーション コントローラーを指すようにするにはどうすればよいですか?
----更新----- OK Ive は、ルート ビュー コントローラー (タブ バー コントローラー) を含む nib ファイルを作成しました。タブ バー コントローラーには、2 つのビュー コントローラーと、ビュー コントローラーを含むナビゲーション コントローラーが含まれています。ナビゲーション コントローラーのビュー コントローラーを、テーブルビューを含むビューにリンクします。プログラムを実行してテーブルビューのタブをクリックしようとすると、次のエラーが表示されます。
2012-04-29 17:23:28.116 ash[6778:f803] -[UIViewController tableView:numberOfRowsInSection:]: インスタンス 0x68bb8d0 に送信された認識されないセレクター 2012-04-29 17:23:28.117 ash[6778:f803] *アプリの終了キャッチされない例外 'NSInvalidArgumentException' のため、理由: '-[UIViewController tableView:numberOfRowsInSection:]: 認識されないセレクターがインスタンス 0x68bb8d0 に送信されました'
テーブルビューを含む私のView Controllerは、実装するUIViewControllerです
その m ファイルには、次のメソッドが含まれています。
#pragma mark -
#pragma mark Table View Data Source Methods
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
return [self.portfolioArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *SimpleTableIdentifier = @"CellTableIdentifier";
static BOOL nibsregistered = NO;
if (!nibsregistered) {
UINib *nib = [UINib nibWithNibName:@"ASHInstrumentCell" bundle:nil];
[tableView registerNib:nib forCellReuseIdentifier:SimpleTableIdentifier];
nibsregistered = YES;
}
ASHInstrumentCell *cell = [tableView dequeueReusableCellWithIdentifier:
SimpleTableIdentifier];
NSUInteger row = [indexPath row];
cell.type.text = [portfolioArray objectAtIndex:row];
return cell;
}
#pragma mark -
#pragma mark Table Delegate Methods
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
NSString *rowValue = [portfolioArray objectAtIndex:row];
NSString *message = [[NSString alloc] initWithFormat:
@"You selected %@", rowValue];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Row Selected!"
message:message
delegate:nil
cancelButtonTitle:@"Yes I Did"
otherButtonTitles:nil];
[alert show];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (void)tableView:(UITableView *)tableView commitEditingStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
NSUInteger row = [indexPath row]
[self.portfolioArray removeObjectAtIndex:row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic] ;
}
私は何を間違っていますか?