use*_*646 7 xcode objective-c ios
这是我的代码,用于调用包含在UINavigationController中的新视图控制器.我想在restaurantResults控制器上有一个简单的后退按钮.我的选择器似乎不起作用.我尝试过使用pop命令.这些工作是否可以使用presentViewController,而不是任何类型的推送?
很确定我的选择器现在是错的,因为它说的是self.navigationController,它可能不对.
这是我调用新视图控制器并设置后退按钮的位置:
- (void)searchBarSearchButtonClicked:(UISearchBar *)foodNearSearchBar
{
restaurantsViewController *restaurantResults = [[restaurantsViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:restaurantResults];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back"
style:UIBarButtonItemStyleBordered
target:nil
action:@selector(backPressed:)];
restaurantResults.navigationItem.leftBarButtonItem = backButton;
[self presentViewController:navController animated:YES completion:Nil];
}
Run Code Online (Sandbox Code Playgroud)
这是我的选择器:
-(void)backPressed: (id)sender
{
[self.navigationController popViewControllerAnimated: YES]; // or popToRoot... if required.
}
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
- (void)backPressed:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
};
Run Code Online (Sandbox Code Playgroud)
小智 2
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back"
style:UIBarButtonItemStyleBordered
target:nil
ction:@selector(backPressed:)];
restaurantResults.navigationItem.leftBarButtonItem = backButton;
Run Code Online (Sandbox Code Playgroud)
这些代码应该用在restaurantViewController上;目标是自我。