我有以下问题。我在我的 Appdelegate 中制作了一个 UIButton,我希望该按钮将我导航到另一个 ViewController。我已经从我的 Storyboard 建立了连接,这个连接是一种 Modal Segue 类型。我认为 performSegueWithIdentifier 会完成这项工作,但它给了我以下错误“没有带有标识符 'showCamera' 的 segue”。而且我很确定我已经通过 Storyboard 制作了那个标识符。
let camera = UIButton.buttonWithType(UIButtonType.Custom) as UIButton
camera.addTarget(self, action: "takePicture:", forControlEvents: .TouchUpInside);
//this function works
func takePicture(sender: UIButton!){
println("Open Camera")
//this throws an error
self.window?.rootViewController?.performSegueWithIdentifier("showCamera", sender: self)
}
最佳答案
不要在 appDelegate 中添加任何 View 组件。只需将 UIViewController 设置为窗口的 rootViewController 即可。然后将按钮添加到 UIViewController。像这样,
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
[self.window makeKeyAndVisible];
ViewController *vc = [[ViewController alloc]init];
UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:vc];
self.window.rootViewController = navController;
// Override point for customization after application launch.
return YES;
}
在 ViewController.m 中添加所需的 UI 组件。
关于ios - 通过 UIButton 从 Appdelegate 导航到另一个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29250903/