I have a problem in iOS7 where I am calling a segue with performSegueWithIdentifier (I have code just like this that works just about everywhere else), then I log the segue in prepareForSegue, then I log again the view controller (VC) that the segue is supposed to push to the top.
prepareForSegue gets called appropriately and the segue has the correct string as its identifier property. Yet the VC that it is supposed to push to the top never gets initialized nor viewWillAppear gets called.
The segue I am talking about, which is the only one that does not work (all the other ones work in both ios6 and 7), is the one leading form the center VC to the right VC. By the way, this works flawlessly in iOS6.
What could be the cause?
the code:
-(IBAction)gotoMainMenu:(id)sender{
DLog(#"DifferentName");
[self performSegueWithIdentifier:#"DifferentName" sender:self];
}
Get in the habit of not wiring up segue's to buttons. Wire them up to the VC and then in the touchUpInside action, fire off the performSegueWithIdentifier.
I had the same issue and solved it as follows. In view A I had a segue that was triggered by a button (UIButton) and the button was also connected to an action in my controller. When I clicked the button in View A, View B would appear as expected. However, when I tried clicking a button in View B to go to View C nothing happened just as you described above.
In my case the issue was resolved in View A. I removed the segue that was tied to the button and let the IBAction that was associated with the button handle calling the performSegueWithIdentifier, then I created a new manual segue that was only tied to the view and voila things worked as expected again.
In short, I guess make sure you don't have both and action and a segue linked to the same button. Hope this helps.
Related
I use three view controllers and on each view controller I put UITableView and UITableViewCell. When I connected from the first view controller's table view cell to another view controller's from within storyboard and ran the simulator, the segue works as expected. However, when I connect from the second view controller's table view cell to the last view controller from within storyboard IN THE EXACTLY SAME WAY as the first one, then for some reasons the transition doesn't work.
If I define didSelectRowAtIndexPath: and within it call [self performSegueWithIdentifier:#"showDetail" sender:self]; in the second view controller's implementation file, the transition can work as expected. I don't care about whether it's storyboard segue or methods defined in my code to perform the transition, as long as the transition does work correctly.
However, I'd still like to know why such inconsistency occurs. As I said, I connected two storyboard in the exactly same way in both cases and checked out attribute inspector and connection inspector, but I don't find any differences between the two connection there.
Also, while the first view controller can perform the transition without the method being defined, when I define it then the transition doesn't work, issuing the following error message:
Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
I think I cannot use both approaches (i.e. storyboard segue and method calls) - I just wanted to know what derives the inconsistency here.
I use iOS 7 and Xcode 5.
First of all, if you use push segues, you can't make a push for the second segue if the first segue is modal (unless you embed your second VC in a navigation controller).
Second, make sure de segue identifiers are unique for each segue.
If you ctrl+drag a segue in storyboard, don't call performsegue in code, you just attempt to do the same operation twice. If the segue is in storyboard, in code you should use prepareforsegue delegate.
Another way of doing all of this is not using any segue in storyboard, then in code #didselectrowatindexpath you can instantiate your destination vc using [storyboard instantiateviewcontrolerwithidentifier...], then [self.navigationcontroller pushviewcontroller..] for a push segue or [self presentviewcontroller...] for a modal.
EDIT: Also, when you ctrl+drag, make sure you are dragging from the cell and not from the table.
Self Answer
I finally found out that the issue was not caused in storyboard - it's on the implementation code. Since I have to use UITableViewCellStyleValue1, I cannot use dequeueReusableCellWithIdentifier, and for some reasons the dequeueReusableCellWithIdentifier has to be used in order to make an automatic transition from cell to another view controller from within storyboard only. I checked out that using dequeueReusableCellWithIdentifier and disabling UITableViewCellStyleValue1 temporarily makes it successful to make the transition without didSelectRowAtIndexPath: method being defined.
I'm having a weird issue with a navigation controller's back button animation:
my app has a tab bar control with 3 tabs, one of them has a navigation controller with two subsequent view controllers, the first one just show a master table and the second one details, the problem comes when I tap the back button from the detail view controller, instead of slide back to the master view controller it just pops the view without animation.
I've noticed that if I first go to another tab, and then return again to this one, the animation will trigger normally.
I've rebuilt the whole app navigation from scratch but the problem still persist, any help is appreciated.
Thanks in advance!.
Edit: More info added
This is how my storyboard looks like in that particular branch:
Here's the prepareForSegue from "Partidos Activos" view controller:
#pragma mark - Segues
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:#"PartidosEnDia"]) {
PartidosActivosEnFecha *paf = segue.destinationViewController;
CalendarCell *senderCell = (CalendarCell *)sender;
paf.datos = senderCell.dataDic;
}
}
Both viewController viewDidLoad methods are calling super at the start of the method.
As I told before, if I just tap on other tab and then come back to this one, the slide back animation from "Partidos Activos En Fecha" viewController works as expected, it's only when I start the application and go directly to this viewController when the slide back animation doesn't work, and it just gets to the caller viewController without animation.
Hope I added enough info, if not just tell me and I will add it again.
I finally found where the problem was, I was missing a call to super in the viewDidAppear method but in UITabBarController!, I was checking only viewControllers for the tabs but not the tabbarviewcontroller. #rdelmar was right.
I had the exact same problem. The cause for me was an empty viewDidAppear:animated method in my UITabBarController. Once I deleted that method, the animation worked normally again.
I think this it's what you want. If I understand, your problem is handle the stack of the navigation controller right? So, check that link.
On my app's start up, it programmatically shows a LoginViewController using a segue. The view controller is presented modally with transition set to cross dissolve. Upon successful authentication, I want to dismiss the login view by programmatically triggering an unwind segue. So I added this to my header file:
- (IBAction)unwindSegue:(UIStoryboardSegue *)segue;
now in IB I'm able to control-drag from the "File's Owner" LoginViewController to the Exit button and choose unwindSegue:. This creates a manual segue, it shows up in the Connections inspectors for the File's Owner and the Exit button correctly. I then click on the newly created Unwind segue from the scene in IB and then give it a name. If I click on the "go to" button for the unwind segue action it takes me to the declaration mentioned above.
So far so good, I then trigger this unwind segue upon successful authentication in my GCD block:
....
dispatch_async(dispatch_get_main_queue(), ^
{
[self performSegueWithIdentifier:#"UnwindSegueIdentifier" sender:self];
[self.spinner removeFromSuperview];
self.spinner = nil;
});
.....and nothing happens when it runs. The spinner does get removed correctly, but there's no sign of that unwind segue executing.
A break point in the implementation of unwindSegue: never gets hit. There are no errors thrown. Nothing gets written to the console. The identifier is correct, I triple checked (otherwise it will fail anyway).
I looked at the answers here, here and here but I don't seem to have missed anything.
What I did notice though, is that Xcode thinks unwindSegue: is not linked:
I'm unable to drag from the little empty circle in front of unwindSegue: and link it to the Exit button.
Any help will be appreciated.
If you are using a modal segue to go to your login view, all you need to go back is to call
[self dismissViewControllerAnimated:YES completion:nil];
More precisely, you should call it at the presenting controller (your first controller), but it will be forwarded if you call at at the presented controller. You can use the completion block do any required clean up. There is no need to use GCD.
EDIT
To answer the additional comment: I'm not really sure from your description, but it seems you've implemented the unwind action at the presented controller instead at the presenting controller. Unwind segues are to allow to do something at the caller (e.g., setting data) without an additional protocol.
Quoting text from Apple's Technical Note on Unwind Segue:
To add an unwind segue that will only be triggered programmatically, control+drag from the scene's view controller icon to its exit icon, then select an unwind action for the new segue from the popup menu.
Link to the Technical Note
I have a Master/Detail view which opens a popover view via storyboard segue. There is an add button on the navigation bar of the Master view controller which works fine.
I added an editing mode where the same popover is invoked by selecting a table cell in edit mode. It fails from the [self performSegueWithIdentifier:#"addQuery" sender:self]; statement. The viewDidLoad in the popover is invoked, but after that the exception is thrown.
I am not invoking presentPopoverFromBarButtonItem - it seems to be coming from the performSegueWithIdentifier.
There is no question that the Master View Controller has a window - a table cell for that view was clicked to start the whole process that is failing.
The popover is the beginning of a navigation controller sequence, which may be part of the problem. Everything is working fine when it really is invoked by the button, just trying to programmatically invoke it is failing.
I have tried changing the "sender" for the performSegueWithIdentifier to no avail.
I suspect the problem has to do with the segue not being invoked by a button, and I do not know how to fake that out.
Any ideas?
There appear to be some bugs in how ipad popover segue's work - see Wayne Hartman's blog post
A simple test revealed that viewWillAppear is being called after viewDidLoad.
I think I understand the problem... havent' worked out the solution yet.
The order in which the methods were called are...
[initiate segue]
viewDidLoad
prepareForSegue
viewWillAppear
I moved my initialization code to the viewWillAppear method - and it worked.
In general, I feel it may be a good idea to initialize within viewWillAppear instead of viewDidLoad anyway.
I have a similar issue:
I am using UIDocumentInteractionController to open a kaynote document in Kaynote app. I was using same code:
[docController presentOpenInMenuFromBarButtonItem:_actionBarButtonItem animated:YES];
Code above was opening popover from actiobBarButtonItem with options what app I would like to use to open my file. If I same thing from DetailViewController I get same error message as author of this thread: "Popovers cannot be presented from a view which does not have a window"
And I was able to find a quick solution for my issue . I am not sure if it will be relevant to yours. Instead of using "presentOpenInMenuFromBarButtonItem" I used "presentOpenInMenuFromRect" and thats it. You just need to define right place for popover to apear
Perhaps I am missing something simple. I added a modal segue from a button to a view controller. I then added some steps to prepareForSegue (and checked I had named the segue correctly). I have done this a few other times with no problem.
Now, when I click the button, the modal window opens, but the prepareForSegue does not fire. I tried putting a log statement in the prepareForSegue before it even checks the description of the label (so theoretically it should fire for any segue). But I get nothing logged.
Any ideas?
Connecting a segue from a button to the next controller is the correct way to connect it, just remember that prepareForSegue: is called on the VC that owns the button not the incoming controller. You get the incoming controller by calling [segue destinationViewController].
Well I found the rookie error I suspected. I duplicated a VC and forgot to set it's class to my new VC class.
Wire up the Segue to the VC not the button. Then in the touchUpInside event, put
[self performSegueWithIdentifier:#"segueid" sender:nil];
I almost always wire the segue up to either the VC or a tableviewcell (if I am using a static cell TV)
You should set cell's reuse identifier set before segue is called.
I tried lots of solutions like above
and checked VC settings
but didn't set the prototype cell's reuse identifier.
Only after I set this to "Cell" , it worked finally.