2015-03-25 78 views
1

我遇到以下問題。我在Appdelegate中創建了一個UIButton,並且我希望該按鈕能夠導航到另一個ViewController。我已經與Storyboard建立了連接,這個連接是一個Modal Segue類型的連接。我認爲performSegueWithIdentifier會做這項工作,但它給了我以下錯誤「沒有標識符showCamera'的繼續」。而且我很確定我已經通過故事板製作了標識符。從Appdelegate通過UIButton導航到另一個視圖

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) 
     } 

如果有人能幫助我,這將是非常gratefull。

+0

爲什麼從AppDelegate初始化? – 2015-03-25 09:09:03

+0

你有什麼建議? @ Dato'MohammadNurdin 我在UITabbar中做了一個自定義按鈕,所以我可以謹慎地調用UIPickerController。我必須在appdelegate中創建該按鈕,因爲我的tabbar已在那裏初始化。如果您有任何其他建議,那麼會更受歡迎。 – Navid 2015-03-25 09:18:35

回答

0

不要在appDelegate中添加任何視圖組件。只需將UIViewController設置爲window的rootViewController即可。然後將按鈕添加到UIViewController.Like this,

- (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組件。

+0

我在Swift工作,你提供的例子是在Objective C中。Swift沒有實現文件。 – Navid 2015-03-25 09:57:38

相關問題