通常、viewController がプッシュされた後、特定のことをしたいと思います。たとえば、電話機能を追加するには、ビジネスの編集を開いて電話フィールドにフォーカスを設定します。
viewController がプッシュされた後、ユーザーが [戻る] ボタンを押すのが早すぎると、アプリがクラッシュします。
そうするための標準的な方法は何ですか?
これはコードです:
+(BGBusinessEditViewController *) pushNewEditViewControllerWithBizandReturnValue: (Business *)biz withNavController :(UINavigationController *) nav andSelectPhone:(BOOL) selectPhoneAfterward
{
BGBusinessEditViewController * editBusiness = [[BGBusinessEditViewController alloc]init];
//[editBusiness view];//load the stuff first
[nav vPushViewController:editBusiness animated:YES andPerformBlock:^{
if (biz) {
editBusiness.biz=biz; //viewDidload must be called first before setting bizs
}
if (selectPhoneAfterward)
{
[editBusiness selectPhone];
}
}];
return editBusiness;
}
-(void) selectPhone
{
NSIndexPath * ipth =[NSIndexPath indexPathForItem:BGBusinessEditTextPhoneNumber inSection:0];
[self.tableView selectRowAtIndexPath: ipth animated:NO scrollPosition:UITableViewScrollPositionTop];
[self tableView:self.tableView didSelectRowAtIndexPath:ipth];
}
基本的に、ナビゲーションコントローラーが既に到達している場合にのみコードを実行するナビゲーションビューコントローラーでカテゴリを作成しました- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated;