回到xcode 5 storyboard中的上一个ViewController

问题描述 投票:0回答:2

我正在尝试在我的iPhone应用程序上创建一个后退按钮,我想回到我的着陆视图..我正在使用此代码,但它不起作用

UIButton *back = [UIButton buttonWithType:UIButtonTypeCustom];
[back setFrame:CGRectMake(0, 0, 24, 24)];
[back setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
[back addTarget:self action:@selector(goback) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *btnBack = [[UIBarButtonItem alloc] initWithCustomView:back];
self.navigationItem.hidesBackButton= YES;
navEng.leftBarButtonItem = btnBack; 


-(void)goback{ [self.navigationController popToRootViewControllerAnimated:YES]; }
ios7 xcode5
2个回答
0
投票

试试这....改变了最后一行代码

UIButton *back = [UIButton buttonWithType:UIButtonTypeCustom]; [back setFrame:CGRectMake(0, 0, 24, 24)]; [back setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
[back addTarget:self action:@selector(goback) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *btnBack = [[UIBarButtonItem alloc] initWithCustomView:back];
self.navigationItem.hidesBackButton= YES;
self.navigationItem.leftBarButtonItem = btnBack;

-(void)goback
{
     [self.navigationController popToRootViewControllerAnimated:YES]; 
}

0
投票

navEng在头文件中声明为IBoutlet UINavigationItem,后退按钮出现并且操作处理正确但导航到之前的ViewController不起作用

@property (nonatomic, strong) IBOutlet UINavigationItem *navEng;
UIButton *back = [UIButton buttonWithType:UIButtonTypeCustom];
    [back setFrame:CGRectMake(0, 0, 24, 24)];
    [back setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
    [back addTarget:self action:@selector(goback) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *btnBack = [[UIBarButtonItem alloc] initWithCustomView:back];
    self.navigationItem.hidesBackButton= YES;
    navEng.leftBarButtonItem = btnBack;



  -(void)goback{
       NSLog(@"back");
       [self.navigationController popViewControllerAnimated:YES];
    }
© www.soinside.com 2019 - 2024. All rights reserved.