Navigate to another view from Appdelegate through a UIButton












1















I have the following issue. I have made a UIButton in my Appdelegate and I want that button navigate me to another ViewController. I already made a connection from my Storyboard, this connection is a type Modal Segue. I thought that performSegueWithIdentifier will do the job but it gives me the following error "has no segue with identifier 'showCamera' ". And I'm pretty sure that I have made that Identifier trough the 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)
}









share|improve this question

























  • Why init from AppDelegate?

    – Mohammad Nurdin
    Mar 25 '15 at 9:09











  • What do you suggest? @Dato'MohammadNurdin I have made a custom Button in my UITabbar so i can call the UIPickerController cautiously. I've to make that button in the appdelegate because my tabbar is initialized there. If you have any other suggestion that would be more then welcome.

    – Navid
    Mar 25 '15 at 9:18


















1















I have the following issue. I have made a UIButton in my Appdelegate and I want that button navigate me to another ViewController. I already made a connection from my Storyboard, this connection is a type Modal Segue. I thought that performSegueWithIdentifier will do the job but it gives me the following error "has no segue with identifier 'showCamera' ". And I'm pretty sure that I have made that Identifier trough the 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)
}









share|improve this question

























  • Why init from AppDelegate?

    – Mohammad Nurdin
    Mar 25 '15 at 9:09











  • What do you suggest? @Dato'MohammadNurdin I have made a custom Button in my UITabbar so i can call the UIPickerController cautiously. I've to make that button in the appdelegate because my tabbar is initialized there. If you have any other suggestion that would be more then welcome.

    – Navid
    Mar 25 '15 at 9:18
















1












1








1








I have the following issue. I have made a UIButton in my Appdelegate and I want that button navigate me to another ViewController. I already made a connection from my Storyboard, this connection is a type Modal Segue. I thought that performSegueWithIdentifier will do the job but it gives me the following error "has no segue with identifier 'showCamera' ". And I'm pretty sure that I have made that Identifier trough the 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)
}









share|improve this question
















I have the following issue. I have made a UIButton in my Appdelegate and I want that button navigate me to another ViewController. I already made a connection from my Storyboard, this connection is a type Modal Segue. I thought that performSegueWithIdentifier will do the job but it gives me the following error "has no segue with identifier 'showCamera' ". And I'm pretty sure that I have made that Identifier trough the 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)
}






ios iphone swift uibutton uistoryboardsegue






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 6:24









Cœur

18.5k9110148




18.5k9110148










asked Mar 25 '15 at 8:40









NavidNavid

3001720




3001720













  • Why init from AppDelegate?

    – Mohammad Nurdin
    Mar 25 '15 at 9:09











  • What do you suggest? @Dato'MohammadNurdin I have made a custom Button in my UITabbar so i can call the UIPickerController cautiously. I've to make that button in the appdelegate because my tabbar is initialized there. If you have any other suggestion that would be more then welcome.

    – Navid
    Mar 25 '15 at 9:18





















  • Why init from AppDelegate?

    – Mohammad Nurdin
    Mar 25 '15 at 9:09











  • What do you suggest? @Dato'MohammadNurdin I have made a custom Button in my UITabbar so i can call the UIPickerController cautiously. I've to make that button in the appdelegate because my tabbar is initialized there. If you have any other suggestion that would be more then welcome.

    – Navid
    Mar 25 '15 at 9:18



















Why init from AppDelegate?

– Mohammad Nurdin
Mar 25 '15 at 9:09





Why init from AppDelegate?

– Mohammad Nurdin
Mar 25 '15 at 9:09













What do you suggest? @Dato'MohammadNurdin I have made a custom Button in my UITabbar so i can call the UIPickerController cautiously. I've to make that button in the appdelegate because my tabbar is initialized there. If you have any other suggestion that would be more then welcome.

– Navid
Mar 25 '15 at 9:18







What do you suggest? @Dato'MohammadNurdin I have made a custom Button in my UITabbar so i can call the UIPickerController cautiously. I've to make that button in the appdelegate because my tabbar is initialized there. If you have any other suggestion that would be more then welcome.

– Navid
Mar 25 '15 at 9:18














1 Answer
1






active

oldest

votes


















0














Don't add any view components in appDelegate. Just set UIViewController as rootViewController of window. Then add buttons to the 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;
}


In ViewController.m add your required UI components.






share|improve this answer
























  • I'm working in Swift the example you provided is in Objective C. Swift doesnt have Implementation files.

    – Navid
    Mar 25 '15 at 9:57











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f29250903%2fnavigate-to-another-view-from-appdelegate-through-a-uibutton%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Don't add any view components in appDelegate. Just set UIViewController as rootViewController of window. Then add buttons to the 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;
}


In ViewController.m add your required UI components.






share|improve this answer
























  • I'm working in Swift the example you provided is in Objective C. Swift doesnt have Implementation files.

    – Navid
    Mar 25 '15 at 9:57
















0














Don't add any view components in appDelegate. Just set UIViewController as rootViewController of window. Then add buttons to the 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;
}


In ViewController.m add your required UI components.






share|improve this answer
























  • I'm working in Swift the example you provided is in Objective C. Swift doesnt have Implementation files.

    – Navid
    Mar 25 '15 at 9:57














0












0








0







Don't add any view components in appDelegate. Just set UIViewController as rootViewController of window. Then add buttons to the 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;
}


In ViewController.m add your required UI components.






share|improve this answer













Don't add any view components in appDelegate. Just set UIViewController as rootViewController of window. Then add buttons to the 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;
}


In ViewController.m add your required UI components.







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 25 '15 at 9:51









Jaffer SheriffJaffer Sheriff

731525




731525













  • I'm working in Swift the example you provided is in Objective C. Swift doesnt have Implementation files.

    – Navid
    Mar 25 '15 at 9:57



















  • I'm working in Swift the example you provided is in Objective C. Swift doesnt have Implementation files.

    – Navid
    Mar 25 '15 at 9:57

















I'm working in Swift the example you provided is in Objective C. Swift doesnt have Implementation files.

– Navid
Mar 25 '15 at 9:57





I'm working in Swift the example you provided is in Objective C. Swift doesnt have Implementation files.

– Navid
Mar 25 '15 at 9:57




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f29250903%2fnavigate-to-another-view-from-appdelegate-through-a-uibutton%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python