0

I am trying to display a view that contains details of the user's account. Being fairly new to iOS development, the following code is what should work (based the docs and searches). Yet, the application crashes and I get a an error stating unrecognized selector:

2012-03-13 16:32:25.616 UrbanAgendaApp[4993:207] Displaying profile view
2012-03-13 16:32:25.635 UrbanAgendaApp[4993:207] -[UAFirstViewController presentViewController:animated:completion:]: unrecognized selector sent to instance 0x4b45240
2012-03-13 16:32:25.674 UrbanAgendaApp[4993:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UAFirstViewController presentViewController:animated:completion:]: unrecognized selector sent to instance 0x4b45240'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x00fbabe9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x0110f5c2 objc_exception_throw + 47
    2   CoreFoundation                      0x00fbc6fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x00f2c366 ___forwarding___ + 966
    4   CoreFoundation                      0x00f2bf22 _CF_forwarding_prep_0 + 50
    5   UrbanAgendaApp                      0x00002308 -[UAFirstViewController showProfileView] + 168
    6   UrbanAgendaApp                      0x00002254 -[UAFirstViewController myUaBtnTouch:] + 52
    7   UIKit                               0x00014a6e -[UIApplication sendAction:to:from:forEvent:] + 119
    8   UIKit                               0x000a31b5 -[UIControl sendAction:to:forEvent:] + 67
    9   UIKit                               0x000a5647 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
    10  UIKit                               0x000a41f4 -[UIControl touchesEnded:withEvent:] + 458
    11  UIKit                               0x000390d1 -[UIWindow _sendTouchesForEvent:] + 567
    12  UIKit                               0x0001a37a -[UIApplication sendEvent:] + 447
    13  UIKit                               0x0001f732 _UIApplicationHandleEvent + 7576
    14  GraphicsServices                    0x00cbea36 PurpleEventCallback + 1550
    15  CoreFoundation                      0x00f9c064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
    16  CoreFoundation                      0x00efc6f7 __CFRunLoopDoSource1 + 215
    17  CoreFoundation                      0x00ef9983 __CFRunLoopRun + 979
    18  CoreFoundation                      0x00ef9240 CFRunLoopRunSpecific + 208
    19  CoreFoundation                      0x00ef9161 CFRunLoopRunInMode + 97
    20  GraphicsServices                    0x00cbd268 GSEventRunModal + 217
    21  GraphicsServices                    0x00cbd32d GSEventRun + 115
    22  UIKit                               0x0002342e UIApplicationMain + 1160
    23  UrbanAgendaApp                      0x00001c2a main + 170
    24  UrbanAgendaApp                      0x00001b75 start + 53
    25  ???                                 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'

The method where this occurs is in a method in FirstViewController, which gets called as a result of a touch up event inside a button:

-(void)showProfileView {
    NSLog( @"%@", @"Displaying profile view" ); // ***

    UAProfileView *profileView = [[UAProfileView alloc] init];

    [self presentViewController:profileView animated:TRUE completion:0];
}

This UAProfielView is a subclass of UIViewController and was was created along with an appropriate .xib file.

So the question is, how do I display this new view in my iPhone application? Using a storyboard is not an option because I have to support iOS 4.0.

Mike D
  • 4,938
  • 6
  • 43
  • 99

3 Answers3

3

The documentation for presentViewController:animated:completion: states that it is only supported on iOS 5.0 and up. You mentioned support for iOS 4.0.

Try presentModalViewController:animated: instead. Alternatively, use a nagivationController and do pushViewController:animated:

amattn
  • 10,045
  • 1
  • 36
  • 33
2

@Mike, make sure you connected the nib to the file's owner.

apalvai
  • 587
  • 5
  • 11
1

Presumably, the base class of UAFirstViewController is also UIViewController? Are you getting any warnings when you build?

I would personally use completion:nil, but I don't think that will make a difference.

So, if you are getting no warnings, then turn zombies on and see if you are dealing with a dead object. Instructions are here

How to enable NSZombie in Xcode?

Run the program and see if you get a zombie warning in the console. If that's the case, then the memory management is wrong.

If all of that is ok, post the code where you call showProfileView.

Community
  • 1
  • 1
Lou Franco
  • 87,846
  • 14
  • 132
  • 192