ビューコントローラーに1つのテーブルビューがあり、その中にcustomTableViewCellがあります。カスタムビューセルにランタイムを生成する動的ボタンがあります。そのボタンをクリックすると、カスタムテーブルビューセルを持つテーブルビューコントローラーを保持しているビューコントローラーを別のビューにプッシュしたいコントローラーなのでどうすればいいですか?私のcustometableviewcell.m
ファイルには、このボタンがあります。
CommentButton = [[UIButton alloc]init];
CommentButton.frame = CGRectMake(CommentLabel.frame.origin.x+CommentLabel.frame.size.width+5, 5, 110, 35);
CommentButton.titleLabel.font = [UIFont systemFontOfSize:12];
[CommentButton setTitle:@"Add Comment" forState:UIControlStateNormal];
CommentButton.backgroundColor = [UIColor clearColor];
[CommentButton addTarget:self action:@selector(GoToComment:) forControlEvents:UIControlEventTouchUpInside];
customtableviewcell.m
以下は、コメントボタンのクリックで呼び出されるファイル内の私の事後通知です
-(IBAction)GoToComment:(id)sender {
[[NSNotificationCenter defaultCenter] postNotificationName:@"GoToComment" object:nil];
}
上記は、私が登録したこのボタンでNSNotification
、次のメソッドと呼ばれます
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(GotoComents)
name:@"GoToComment" object:nil];
上記の行は、そのcustomtableviewcellでテーブルビューを持っているviewcontrollのviewdidloadにあります。
そしてcustomtableviewセルから、新しいView Controllerをプッシュする上記の通知を投稿しています
-(void)GotoComents
{
TableTextViewController *settingView=[[TableTextViewController alloc]initWithNibName:@"TableTextViewController" bundle:nil];
[self.navigationController pushViewController:settingView animated:YES];
}
今、私はcustomTableViewcellから呼び出してviewcontrollerメソッドを呼び出すnsnotoficationセンターでそれをやったところです。
しかし、それは正しい方法ですか?そうでない場合は、どうすればこれを達成できるか教えてください。ランタイムを生成する動的ボタンがあることを覚えています。