UIViewController: loadView loads multiple times why???

Discussion in 'iOS Programming' started by belsokar, Jul 31, 2008.

  1. belsokar, Jul 31, 2008
    Last edited by a moderator: Dec 8, 2011

    macrumors member

    Joined:
    Jul 21, 2005
    #1
    So, I have a basic UITableViewController that navigates to a UIViewController from the table's row objects.

    so: UITableView.Row -> (selected) -> opens UIViewController View.

    When I open the UIViewController view, I do a database call to look up some details for the object id that was selected in the parent TableViewController.

    I had one issue however,...whenver I paged back to the previous view via the NavigationController, and selected a new row, the view was not updating the NavigationTitle.

    I found that my original code was only loading once and setting the title of the navigation controller. It never refreshed after the first call to the view:

    Code:
    - (void)viewDidLoad
    {
        self.title = newname;
    }
    I then used the loadView overload instead of the viewDidLoad, and that worked:

    Code:
    - (void)loadView
    {
        self.title = newname;
    }

    Upon debugging however, I found that the 'loadView' method was executed 4 times everytime. While not a major call, just wondering why this is happening. I have stepped through the code line by line and this is what I find.

    I get a bunch of these messages in the console: "Unable to disassemble objc_msgSend."

    Furthermore, when looking at the stack trace, I see the following in my trace:

    Code:
    [UIViewController view]
    [UINaviagationController -startTransition:fromViewController:toViewController:]
    [UINavigationController pushViewController:transition:forceimmediate:]
    [UINavigationController pushViewController:animated:]
    [ViewController tableView:didSelectRowAtIndexPath:]
    Essentially, all I'm looking for is a way to have the view refreshed with the new data after the data has been loaded. It's working, but I'm not sure this is what it's supposed to do!
     
  2. Yogachitra, Jun 26, 2009
    Last edited by a moderator: Dec 8, 2011

    macrumors newbie

    Joined:
    Jun 26, 2009
    #2
    Any solution to this?

    Hey,

    I'm facing the same problem now. Have you got any solution for this? if so, can you please help me?

    Thanks in advance.
     
  3. ektas, Nov 13, 2009
    Last edited by a moderator: Dec 8, 2011

    macrumors newbie

    Joined:
    Nov 13, 2009
    #3
    all it requires to set view for the view controller
    which means you need to do as follows

    Code:
    - (void)loadView
    {
    
    self.title = newname;
    
    UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,180)];
    
    // now you can add subview to your view
    // [v addSubView:v1];
    self.view = v;
    
    [v release];
    }
     
  4. reachjoy, Dec 7, 2011
    Last edited by a moderator: Dec 7, 2011

    macrumors newbie

    Joined:
    Dec 7, 2011
    #4
    You need to call [super loadView] if using the method loadView. It is better to use the method viewDidLoad instead. In such case comment or delete the method loadView.

    Code:
    -(void)loadView
    {
        [super loadView];
        //code 
    }
     
  5. macrumors 65816

    Joined:
    May 1, 2010
    Location:
    California
    #5
    Forget all the viewload stuff, I wanna know how you got 6,200 views on this thread! :eek:

    If you can do that with an app... you'd be RICH!!


    Ok, I get it...
    Take a thread from 3.5 years ago, and answer it! Works every time :rolleyes:

    Let's all wait and see if belsokar from 2008 chimes back in on this one.
     
  6. macrumors newbie

    Joined:
    Dec 7, 2011
    #6
    I am a newbie on iOS development, I got the same issue yesterday and I searched , found this thread. But I found noone answered this yet. But after some time I got it fixed by the described method. So I thought it will be good if I post my solution.. Anyway I am not at all worried about the numbers here
     

Share This Page