Segue transition from table view cell to another view controller works only some arbitrary times - why?

StackOverflow https://stackoverflow.com//questions/22011206

Вопрос

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.

Это было полезно?

Решение 2

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.

Другие советы

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top