PDA

View Full Version : UIViewController: loadView loads multiple times why???




belsokar
Jul 31, 2008, 01:02 PM
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:

- (void)viewDidLoad
{
self.title = newname;
}

I then used the loadView overload instead of the viewDidLoad, and that worked:

- (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:

[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!



Yogachitra
Jun 26, 2009, 03:12 AM
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:

- (void)viewDidLoad
{
self.title = newname;
}

I then used the loadView overload instead of the viewDidLoad, and that worked:

- (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:

[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!

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.

ektas
Nov 13, 2009, 03:55 AM
all it requires to set view for the view controller
which means you need to do as follows

- (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];
}

reachjoy
Dec 7, 2011, 07:07 AM
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.

-(void)loadView
{
[super loadView];
//code
}

KarlJay
Dec 7, 2011, 08:15 AM
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.

reachjoy
Dec 7, 2011, 11:30 PM
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