【发布时间】:2013-03-25 19:05:56
【问题描述】:
我正在为我的 iOS 应用程序创建一个标题栏,并在 UIView 中创建它。我遇到的唯一问题是“主页按钮”。当home键被按下时,需要跳转到首页,也就是ViewController。
但是,[self presentViewController:vc animated:NO completion:NULL]; 似乎不适用于 UIView。
我该如何解决这个问题?
- (void) createTitlebar {
CGRect titleBarFrame = CGRectMake(0, 0, 320, 55);
//Create the home button on the top right of the page. When clicked, it will navigate to the home page of the application
homeButton = [UIButton buttonWithType:UIButtonTypeCustom];
homeButton.frame = CGRectMake(275, 10, 40, 40);
[homeButton setTag:1];
[homeButton setImage:[UIImage imageNamed:@"homeIcon.png"] forState:UIControlStateNormal];
[homeButton addTarget:self action:@selector(homeButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:homeButton];
}
- (IBAction)homeButtonPressed:(id)sender{
//Transition to the submit button page
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
ViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"ViewController"];
[vc setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentViewController:vc animated:NO completion:NULL];
}
【问题讨论】:
-
您是否将选择器添加到您的按钮? IE。按钮是否知道执行哪种方法?其次,尝试使用 popToRootViewControllerAnimated 来避免循环。
-
我遇到的错误消息是 - 'TitleBar' 没有可见的@interface 声明选择器 presentViewController:animated:completion
-
这个 homeButtonPressed: 方法定义在哪里?它在任何视图控制器或某个视图中吗?
-
确保您的 ViewController 是
UIViewController子类。 -
它是一个
UIViewController子类
标签: ios objective-c xcode ios6 presentviewcontroller