Objective c 如何显示UIActionSheet以确认在导航视图中向后移动
使用Xcode,我有一个可以导航到视图B的视图A 在按下Back UIBarButtonItem时,我尝试向用户展示一个UIActionSheet,以确认导航返回到视图aObjective c 如何显示UIActionSheet以确认在导航视图中向后移动,objective-c,xcode,navigation,uiactionsheet,Objective C,Xcode,Navigation,Uiactionsheet,使用Xcode,我有一个可以导航到视图B的视图A 在按下Back UIBarButtonItem时,我尝试向用户展示一个UIActionSheet,以确认导航返回到视图a 我需要在代码中执行什么操作才能阻止视图向后导航,然后(取决于用户输入)向后移动或停留在当前屏幕上?以编程方式添加backbutton 例如 UIButton *backBtn= [[UIButton alloc] initWithFrame:CGRectMake(0,0,54,30)]; [backBtn addTarget
我需要在代码中执行什么操作才能阻止视图向后导航,然后(取决于用户输入)向后移动或停留在当前屏幕上?以编程方式添加backbutton 例如
UIButton *backBtn= [[UIButton alloc] initWithFrame:CGRectMake(0,0,54,30)];
[backBtn addTarget:self action:@selector(backButtonPressed:)forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *backBarButton = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
[backBtn release];
[[self navigationItem] setLeftBarButtonItem:backBarButton];
[backBarButton release];
//backButtonPressed is the selector for backBtn
然后从该选择器显示操作表,并根据用户导航到上一个viewController或不导航
要导航到上一页,请使用popViewMethod
`您不应该为每个其他操作提供UIActionSheet。最好使用UIAlertView。根据苹果UIActionsheet指南:- 提供完成任务的替代方法。操作表允许您提供在当前任务的上下文中有意义的一系列选择,而无需在用户界面中永久放置这些选择 在完成潜在危险的任务之前获得确认。行动表会提示用户考虑他们将要采取的步骤的潜在危险影响,并为他们提供一些备选方案。这种类型的通信在基于iOS的设备上尤其重要,因为有时用户无意中点击控件 对于UIAlertView:-
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Alert View"
message:@"Do You want to go back to previous screen?"
delegate:self
cancelButtonTitle:@"NO"
otherButtonTitles:@"YES",nil];
[alertView show];
[alertView release];
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0) {
NSLog(@"THE 'NO' BUTTON WAS PRESSED");
}
if (buttonIndex == 1) {
NSLog(@"THE 'YES' BUTTON WAS PRESSED");
}
}
在UINavigationController的后退按钮上执行此操作。根据按下的按钮“是”或“否”,您可以允许导航。还符合UIAlerrtVIewDelegate协议。我已经实现了“backButtonPressed:”方法以及“popToRootViewControllerAnimated”,但是UIBarButton是不可见的:(