0

I'm trying to call a ViewController's segue from AppDelegate by using delegate. I want to make sure that the xmppRoster is stored before the segue is performed. There is an error that says:

"Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver () has no segue with identifier 'segueForList''"

I'm sure segueForList is the correct segue identifier because the code [self performSegueWithIdentifier:@"segueForList" sender:self] works when not using delegate.

The segue is built in a storyboard and connect to the ViewController, I can't post the image now cause my reputation is not enough,sorry

AppDelegate.h:

@protocol friendListSegue
- (void) ListSegue;
@end

@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (assign,nonatomic) id<friendListSegue> delegate;
@end

In AppDelegate.m, this method will automatically be called when system finishes the storage:

- (void)xmppRosterDidEndPopulating:(XMPPRoster *)sender
{
   ViewController * view0=[[ViewController alloc] init];
   self.delegate = view0;
   [self.delegate ListSegue];
   NSLog(@"didStored");
}

ViewController.m:

- (void) ListSegue{
   NSLog(@"segue_List");
   [self performSegueWithIdentifier:@"segueForList" sender:self];
}
MCTam
  • 1
  • 1
  • Where is ViewController made? In a storyboard or xib? In code? – rdelmar Jul 26 '14 at 01:37
  • Segues work in storyboards. Here, you are just initing a view controller in code and expecting it to behave like in a storyboard. – duci9y Jul 26 '14 at 06:36
  • The segue is built in a storyboard and connect to the ViewController, I can't post the image now because my reputation is not enough,sorry – MCTam Jul 26 '14 at 09:13

1 Answers1

0

Allocating and initializing a new ViewController won't give you any of the data in storyboard. You need to load the ViewController in from your nib.

How can I load storyboard programmatically from class?

Still I have to question what you're doing. Even if you want to wait until your roster is done before performing a segue, it might be a better idea to make the ViewController that's performing the segue the delegate of xmppRoster so that you perform the segue from the object that actually has the segue.

Community
  • 1
  • 1
Literphor
  • 498
  • 4
  • 16
  • The method xmppRosterDidEndPopulating only works in the AppDelegate, I don't know how to make it work in the ViewController, if it's what you mean by "make the ViewController that's performing the segue the delegate of xmppRoster" – MCTam Jul 26 '14 at 10:53
  • Well your ViewController that has the segue should also conform to XMPPRosterDelegate protocol, then add it to your XMPPRoster's multicastDelefgate. – Literphor Jul 27 '14 at 16:22