【发布时间】:2014-10-05 15:50:26
【问题描述】:
我创建了一个UIActionSheet 类,它允许我从应用程序中的任何位置注销。我遇到的问题是,一旦我点击注销按钮,它也应该关闭当前的viewController 并返回登录viewController。下面是我的代码的 sn-p。
NSObject.h file
@interface constants : NSObject<UIActionSheetDelegate>{
UIActionSheet *msg;
}
-(void)presentMyActionSheet;
@property (nonatomic, strong) UIView *viewForActionSheet;
NSObject.m file
-(void)presentMyActionSheet{
msg = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Log Out" otherButtonTitles:nil, nil];
[msg showInView:self.viewForActionSheet];
}
// actionsheet delegate protocol item
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex: (NSInteger)buttonIndex{
NSLog(@"button index = %ld", (long)buttonIndex);
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if(buttonIndex == 0){
[defaults setObject:nil forKey:@"acctInfo"];
[defaults setBool:NO forKey:@"isLoggedOn"];
NSLog(@"You logged out");
这是我尝试过的。
viewController *controller = [[viewController alloc]init];
[controller.navigationController popViewControllerAnimated:NO];
[controller dismissViewControllerAnimated:NO completion:nil];
它不起作用。
}else{
NSLog(@"You canceled logout");
}
}
viewController.h file
@interface viewController : UIViewController<UIActionSheetDelegate>
@property(nonatomic, retain)constants *obj;
viewController.m file
@synthesize obj;
{
self.obj = [[constants alloc] init];
self.obj.viewForActionSheet = self.view;
[self.obj presentMyActionSheet];
if([defaults boolForKey:@"isLoggedOn"]){
If I try it from here it crashes.
// [self.navigationController popViewControllerAnimated:NO];
// [self dismissViewControllerAnimated:NO completion:nil];
}
}
关于它为什么不起作用的任何建议?
谢谢
【问题讨论】:
-
您是否尝试过先关闭操作表然后弹出视图控制器?
-
@pnavk 是的,当我尝试应用程序崩溃时。
标签: ios objective-c ios7 uiviewcontroller uiactionsheet