Unable to push views to navigation controller

Discussion in 'iOS Programming' started by blueeye, Sep 28, 2009.

  1. blueeye macrumors member

    blueeye

    Joined:
    Oct 27, 2007
    #1
    Hi all,

    I'm trying to create an application (navigation based, I might add) which loads different xml data in different views.
    The RootViewController loads without problems, but when I select a row I get a variety of errors.
    There are two options: "By Room" and "See All". If I select the first option, it loads the RoomMenuController, and the second loads the EveryoneController.

    On selecting "By Room" I get the following error:

    Code:
    2009-09-28 13:01:43.901 Assisted Living 2.0[3838:207] *** -[UITouchData setParentViewController:]: unrecognized selector sent to instance 0x382b6a0
    2009-09-28 13:01:43.902 Assisted Living 2.0[3838:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UITouchData setParentViewController:]: unrecognized selector sent to instance 0x382b6a0'
    2009-09-28 13:01:43.904 Assisted Living 2.0[3838:207] Stack: (
        29291611,
        2523598665,
        29673531,
        29242998,
        29095618,
        3282295,
        3260859,
        11550,
        3037850,
        3021016,
        274874,
        29076160,
        29072456,
        37377965,
        37378162,
        2764803,
        8640,
        8494
    )
    
    I have no idea how to interpret the stack and I don't know why the problem is caused. I've set breakpoints in the viewDidLoad methods of all the ViewControllers but these methods are never called, so I don't think the problem is in the ViewControllers.

    On selecting the second options I get an EXC_BAD_ACCESS signal which I assume means that it is trying to load something that has already been released. I don't know why this is, however.

    I'm loading my ViewControllers in the following manner:
    Code:
    views = [[NSMutableArray array] init];
    	[views addObject:[[[RoomMenuController alloc] initWithNibName:@"RoomMenu" bundle:[NSBundle mainBundle]] retain]];
    	[views addObject:[[[EveryoneController alloc] initWithNibName:@"Everyone" bundle:[NSBundle mainBundle]] retain]];
    	[views addObject:[[[PeopleByRoomController alloc] initWithNibName:@"PeopleByRoom" bundle:[NSBundle mainBundle]] retain]];
    
    (that's from the viewDidLoad method of RootViewController.m)

    Code:
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    	NSLog(@"navigationController=%@", [self navigationController]);
    	NSLog(@"	before push: stack=%@", [[self navigationController] viewControllers]);
    	NSLog(@"	pushing: %@", [views objectAtIndex:indexPath.row]);
    	UIViewController *ctrl = [views objectAtIndex:indexPath.row];
    	[[self navigationController] pushViewController:ctrl animated:YES];
    	[ctrl release];
    	NSLog(@"	after push : stack=%@", [[self navigationController] viewControllers]);
    }
    
    Any help with this would be much appreciated because I'm stumped but that's probably because I've only been doing this for a few days.
     
  2. blueeye thread starter macrumors member

    blueeye

    Joined:
    Oct 27, 2007
    #2
    The first error has now changed (for some unknown reason) to also be an EXC_BAD_ACCESS signal.
     
  3. blueeye thread starter macrumors member

    blueeye

    Joined:
    Oct 27, 2007
    #3
    I solved the problem by using class properties instead of objects in an array. I'm curious as to why the first method did not work, however, because I don't see why it shouldn't (and I've seen it used in tutorials).
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    The EXC_BAD_ACCESS is caused by this line:
    Code:
    [ctrl release];
    You don't want to release the controller at this point.
     
  5. jnic macrumors 6502a

    Joined:
    Oct 24, 2008
    Location:
    Cambridge
    #5
    Had you meant to write:

    Code:
    views = [[NSMutableArray [COLOR="Red"]alloc[/COLOR]] init];
    
    ?
     
  6. blueeye thread starter macrumors member

    blueeye

    Joined:
    Oct 27, 2007
    #6
    I had it without this before and it did the same thing. The controller can be released because it has been copied already, no?

    @jnic: no I hadn't, but maybe I should have done. I suppose that it's possible that the views had released themselves automatically... I really should have allocated it or used retain.
     

Share This Page