我有一个屏幕有导航栏,后退按钮默认放置在使用navigationItem storyboard。我想根据条件在后退按钮上弹出视图控制器。后退按钮在添加事件之前是默认的。请为此问题提出解决方案。 在没有UINavigationBar标题的后退按钮上添加提醒iOS
回答
如果您设置tintColor中导航栏,添加自定义后退按钮图像无题是着色颜色将反映图像的颜色。请按照这个苹果文档链接。
UINavigationItem *navItem = [[UINavigationItem alloc] init]; navBar.tintColor = self.tintColor;
UIImage *myImage = [UIImage imageNamed:@"left_arrow.png"]; myImage = [myImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithImage:myImage style:UIBarButtonItemStylePlain target:self action:@selector(cancelButtonFunction:)];
navItem.leftBarButtonItem = leftButton;
navBar.items = @[ navItem ];
你应该实现此方法,
-(void)willMoveToParentViewController:(UIViewController *)parent{
if (parent == nil) {
// handle your back button's task here
}
}
这种方法得到的导航之前叫parentview
控制器。
如果它不工作你的情况,那么你可以使用自定义后退按钮类似,
- (void)viewDidLoad {
[super viewDidLoad];
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(goBack:)];
self.navigationItem.leftBarButtonItem=newBackButton;
}
-(void)goBack:(UIBarButtonItem *)sender {
//Handle your back button's task here and you have to call popViewcontroller your self in this case
}
我想要显示警报,然后对警报进行操作,然后弹出视图控制器。 –
我不想要后面的标题,只有后面的箭头。 –
然后添加具有清晰颜色的自定义按钮,并且不要设置标题。只需添加无边框清晰颜色的按钮即可。所以原来的导航栏按钮将可见,并点击自定义按钮上的检测 – Lion
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(goBack:)];
self.navigationItem.leftBarButtonItem=newBackButton;
-(void)goBack:(UIBarButtonItem *)sender {
UIAlertView *removeAddAlertView = [[UIAlertView alloc] initWithTitle:@"Alert!" message:@“Are you want to go Back ” delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:@"Cancel", nil];
[removeAddAlertView show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
// cancel
}else if (buttonIndex == 1) {
// ok
}
}
我不想要后标题,只有后面的箭头。 –
- 1. 删除UINavigationBar后退按钮标题
- 2. 更改UINavigationBar后退按钮标题
- 3. UiNavigationBar后退按钮
- 4. iOS 7 UINavigationBar显示默认后退按钮,无标题
- 5. 在UINavigationBar上缩进后退按钮?
- 6. NavigationController UINavigationBar的后退按钮
- 7. 如何在ios上的UINavigationBar后退按钮上按下后隐藏键盘
- 8. UINavigationBar中的后退按钮标题问题
- 9. UINavigationBar后退按钮消失
- 10. UINavigationBar后退按钮蒙皮
- 11. UINavigationBar,后退按钮和dismissModalViewController
- 12. 显示按下后退按钮上的提醒对话框
- 13. 在UINavigationBar左侧的“后退”按钮旁边添加另一个按钮
- 14. 向我的UINavigationBar的后退按钮添加渐变
- 15. 如何将UINavigationBar后退按钮的标题更改为“返回”
- 16. 如何添加后退按钮到自定义的UINavigationBar
- 17. 如何向我的UINavigationBar添加后退按钮?
- 18. UINavigationBar的后退按钮没有文字和固定大小
- 19. UINavigationBar没有文字的后退按钮,曾经
- 20. UINavigationBar后退按钮标题方向更改
- 21. UINavigationBar barButtonItem更改后退按钮图像和标题
- 22. IOS 9.3禁用iPhone上的后退按钮后退按钮
- 23. 如何以编程方式将后退按钮添加到UINavigationBar?
- 24. 如何手动添加'后退'按钮到UINavigationBar?
- 25. 快速更改按钮标题后的后退按钮标题
- 26. 如何以编程方式在其上添加UINavigationBar和后退按钮
- 27. 当iOS7中的标题太长时,隐藏UINavigationBar后退按钮标题
- 28. UINavigationBar的后退按钮不会出现
- 29. UINavigationBar得到白色的后退按钮
- 30. 没有标题栏或后退按钮正在生成sencha touch
的[当按下的UINavigationController的背面栏按钮执行动作]可能的复制(http://stackoverflow.com/questions/27713747/execute-action-when-back-bar-button被按下) –