Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Photo Browser iPhone App UIKit Dynamics Extra Credit

performSegueWithIdentifier crash

I added a "Done" button to my navigation bar programmatically since I couldn't do it on the storyboard.

Scott provided me with this code to do that: https://www.dropbox.com/s/m7g16cta0zzoaqb/UIBarButton_Scott.png

Next, I want to link from this "Done" button another subclass of UICollectionViewController (both destination and source view controllers are subclasses of UICollectionViewController).

Since, my "Done" button couldn't show up on the storyboard (because added programmatically), I create a new "Done" button on the storyboard just in the purpose of being able to generate a segue identifier between the two view controllers. I assigned the string "donePressed" to the segue identifier as you can see here: https://www.dropbox.com/s/8sd936ml1iably3/donePressed_segue_identifier.png

When I run my build, it succeeds but when I tap on the "Done" button in my navigation bar, I get the following error message: https://www.dropbox.com/s/r5fdg9xs886hxod/Error_Message_performSegueWithIdentifier.png

In essence, it is telling me that my source view controller has no segue with the "donePressed" identifier.

This is weird to me since I purposely created the segue and when I double check my code calling the "performSegueWithIdentifier" method, it looks like I have entered the right "donePressed" NSString.

See here this line of code: https://www.dropbox.com/s/lzdb25y233xht0g/performSegueWithIdentifier_code.png

What am I doing wrong?

Any help much appreciated.

Merci!

24 Answers

Thomas Nilsen
Thomas Nilsen
14,957 Points

I downloaded your project once more and made a recording of me making it work. http://videobam.com/cvjxz (the quality turned out not too great, but hopefully you'll see what I do anyway).

And - sure you can use hybrid (programmatically and storyboards), but not quite like the way you did it in the app delegate. I tend to do things programmatically if I need a reusable view. That's not easy to do with storyboards.

Hope this helps you!

Thomas Nilsen
Thomas Nilsen
14,957 Points

Do you mind sharing the project - that would make it easier to spot the error (at least for me..)

Sure. How can I do that?

Thomas Nilsen
Thomas Nilsen
14,957 Points

upload to dropbox and shre the link here :)

Hi Thomas: Looking forward to your thoughts. Thanks for looking into it.

Here is the link https://www.dropbox.com/sh/cr7fm1iy96d4li0/AADkfJuKapWDgE7DfvKj_nGGa

Please confirm this works for you. Looking to partner up with a more experienced coder to finish it up. I am trying to do something simple. ;)

Thomas Nilsen
Thomas Nilsen
14,957 Points

the link works and I got the project. I'll have a look a little later tonight :)

Merci Thomas!

Thomas Nilsen
Thomas Nilsen
14,957 Points

Pas de problème! But I'm having some problems getting it to run. It's cocoa pod related, But I'll figure it out ;)

Very good French. I am impressed. Let me know if I can assist you in any way.

btw Nilsen is a common name in Denmark. Any origins there?

Thomas Nilsen
Thomas Nilsen
14,957 Points

Thank you! Not that I know of, no. But I know it's quite a common lastname in Norway as well (Where I'm from)

Lol. Great! Beautiful country you are from.

Thomas Nilsen
Thomas Nilsen
14,957 Points

I didn't get to run the project, but having looked at your code, I think I see the problem:

You say you want to perform the segue programmatically, which is fine. But the segue is already connected to a UIBarButton in your storyboard. Remove that just have the UIBarButton added with code, and connect you segue from the entire viewController to the next one in the storyboard instead.

I made a tiny sample project to show you that it works :)

https://www.dropbox.com/s/knl9vsodk4f9idg/segueTest.zip

Thomas: It does work on your demo. But it doesn't work in my project when I follow step by step what you did.

I may not be selecting the entire view controller in the right way?

I tried directly from the center of the view to the next view controller. And I also tried from the UICollectionView yellow icon at the bottom of the source view as well. Renamed the segue to "toPhotosPostedByFriendsViewController", changed my code accordingly and I still get the same error message in both cases: "'Receiver (<THFriendsViewController: 0x127d26f70>) has no segue with identifier 'toPhotosPostedByFriendsViewController''

I guess I am missing something. No so sure what...

Any further ideas appreciated.

Merci!

Thomas Nilsen
Thomas Nilsen
14,957 Points

ineresting, but on the bright side - I just now managed to run your app, so I'll have a thorough look tomorrow :)

That is very nice of you Thomas. Have a great night!

Thomas Nilsen
Thomas Nilsen
14,957 Points

After a lot of testing and debugging I found the mistake. It was in ...... you ready? ...... your APPDELEGATE.M. In that file you called something called "[self customizeUI]" which allocated all the main window, you viewControllers and so on, making you storyboard irrelevant. That's why it never found the segway. I zipped the project so you can have a look, or try it out for yourself. Also, in you storyboard you have a push segway from your navigation controller to you "PhotosPostedByFriendsViewController". that makes no sense, so I removed that :)

https://www.dropbox.com/s/bltt02tz6bi9elo/Gistagram.zip

Thomas: Thanks for looking into this.

If I comment out the customizeUI method, as it appeared to be in your .zip file above, I no longer have any UI displayed. Right?

So not so sure how to proceed...
Here is the code from the customizeUI method, what do I need to change in it to avoid the problem you mentioned?

- (void) customizeUI {

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    THFriendsViewController *photosFriendsViewController = [[THFriendsViewController alloc] init];

    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:photosFriendsViewController];


    UINavigationBar *navigationBar = navigationController.navigationBar;
    navigationBar.barTintColor = [UIColor colorWithRed:255.0 / 255.0 green:160.0 / 255.0 blue:40.0 / 255.0 alpha:1.0];
     navigationBar.barStyle = UIBarStyleBlackOpaque;

    //Set THFriendsViewController as rootViewController may need to revert back to THPhotosViewController
    self.window.rootViewController = navigationController;

    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];

}

In addition, I tried to remove the Navigation Controller where had embedded my custom subclass of UICollectionViewController (since I thought it was required to have a nav bar ==> the code takes care of this already, in the customizeUI method). And I created the segue directly between my two custom subclasses of UICollectionViewController in my storyboard.

I ensured the identifier of this segue matched what I put in my code for the donePressed method in my source custom subclass UICollectionViewController which executes the "performSegueWithIdentifier".

This didn't work either.

I am stuck!
"Completement plante!" would be a good French localization ;)

If you have any other ideas, this would be much appreciated although I already appreciate a lot you taking time to look into this already.

A bientot

Thomas Nilsen
Thomas Nilsen
14,957 Points

It's correct to comment out the customizeUI completely. Once you do that - make sure that the project uses the storyboard:

http://imgur.com/6M4Kmfl

If you ran my zip file - everything should be working - right?

When I ran the version of my project that you modified, the build fails, it looks like I am missing a file.

Here is the error message: https://www.dropbox.com/s/ozipkdylctq56fr/Pods.png

So, if I try to read your feedback correctly, I comment out the customizeUI method, I set the storyboard as the main interface, here is what I get.

1) My custom subclass of UICollectionViewController is not rendered properly and the nav bar lost its customization (unless you matched it in your project, assuming there is a way to do that manually over the storyboard)

Here is what I see: https://www.dropbox.com/s/1613c247igujoq5/NoCustomNav_NotRightCustomSubclass.png

2) The transition works great now.

I can see the second custom subclass of UICollectionViewController (empty because I have yet to work on data model): https://www.dropbox.com/s/k8anpo6qinjwm2w/Transition_works.png

Would anything look any different if I were to manage to run your build?

I really want to maintain the custom elements of the design.

Bonne nuit!

Thomas Nilsen
Thomas Nilsen
14,957 Points

You can customize all that in your storyboard :) http://imgur.com/HJ0utP2

As for your error. I didn't get the same exact one but what I did to make it work, would probably work for you too.

1) Locate the project folder and delete "podfile.lock"

2) Open "terminal" and write "cd <path to project-folder>" (You can usually drag the entire folder right into terminal and the path is displayed)

3) (still in terminal) Write pod install - this will reinstall everything pod related to that project.

4) open Xcode - and run a "clean", then "build" to make sure there are no errors.

5) If not - you can run it :)

In my mind this question is solved. Everything works here - we just have to make it work for you as well ;)

Hi Thomas,

Thank you for your patience...

Everything worked great when I followed your step-by-step instructions. Until 5). The build failed with the same error message. Cannot find the following file:

#import "UIStepper+RACSignalSupport.h"

Hopefully, I'll be able to run your build soon to see what you did besides commenting out the customizeUI method.

In the meantime, I am still curious...

Moving forward, since I now elect to work with the storyboard. As opposed to using only programmatic UI controls and views as Sam did it in the "Photo Bombers" app on treehouse.

In the same way I have to recreate manually on the storyboard the nav bar that I had programmed already, will I also need to recreate manually all other control and view items that I have already programmed?

I put in a lot of time doing that - as per Sam's and Amit's recommendations (photo bombers course + extra credit).

Just very curious on that.

I'd be surprised if there is no "hybrid" way to use both the storyboard and programmed UI elements.

What's the best practice after all?

The early apps on treehouse seemed to recommend using the storyboard (crystall ball, ribbit, blog reader) and as the course moved along it seemed to favor programmatic UI controls and views (photo bombers).

Would value the points of view in the community.

Merci beaucoup!

Thomas: Thank you very much. I have still work to do to better understand the conflicts between the storyboard and the programmatic visual elements.

Right now, I cannot get to have my custom subclass of UICollectionView to initialize properly with the code I had written for it:

objective-c

#import "THFriendsViewController.h"
#import "THFriendPhotoCell.h"
#import <SimpleAuth/SimpleAuth.h>


@interface THFriendsViewController () <UIViewControllerTransitioningDelegate>
@property (nonatomic) NSString *accessToken;
@property (nonatomic) NSArray *friends;
@property (nonatomic) BOOL loading;
@property (nonatomic) UIBarButtonItem *doneButton;

@end

@implementation THFriendsViewController


- (void)setLoading:(BOOL)loading{
    _loading = loading;

    self.navigationItem.rightBarButtonItem.enabled = !_loading;
}

- (instancetype)init {
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake(106.0,106.0);
    layout.minimumInteritemSpacing = 1.0;
    layout.minimumLineSpacing = 1.0;

    return (self = [super initWithCollectionViewLayout:layout]);
}

Anyway, I guess I need to play with it more to understand why I now have 5 images per row (and not 3 as per layout.itemSize above).

I even tried to use the storyboard to set the cell manually to 106, it doesn't solve the issue.

Well, the road ahead is fascinating. Thanks again for your great help and I'll make sure to award you best answer.

Takk!

Thomas Nilsen
Thomas Nilsen
14,957 Points

Ingen problem! (Pas de problème)

Glad it worked out! :)

:)

If you are open to it, we could connect on LI for future synergies: www.linkedin.com/in/mobilegem

Now also following you on twitter with startup handle