Help - Search - Members - Calendar
Full Version: Some help with View Controllers (iPhone SDK)
InsanelyMac Forum > Apple World > Mac Programming and Development
Ilyace
In my app I have 2 UIViewControllers and a UINavigationController set up. In the second view controller, I have a UITableView. I've set the view controller's view to the UITableView (well it's done automatically) and both the delegate and datasource are set to the view controller's class. The problem is that whenever I push from the first view controller to the second, the table view is not visible on the second view controller. How can I fix this?
stroke
I'm sorry — what is the point of pushing to the new view controller if the content will be the same? :s

It changes views... the table view is part of the RootViewController, not your second one.
Ilyace
Wait so there's no way I can make the table view on the second view controller? That's what I'm trying to do.
stroke
Then go into Interface Builder and put a table on it. I'm not quite sure what you're trying to accomplish here.
alloutmacstoday
Well for starters, you don't want to rely on IB for this kind of stuff.

Make a new class that subclasses UITableViewController. It will automatically set itself as data source and delegate. Then, you take the methods from the view controller (the ones you used because it was delegate and data source), and put them into the UITableViewController class. (You do have methods like numberOfRowsInSecton, etc, right?). Then, in the other view controller class (the 1st VC), you have a void action called like push, then when invoked, calls the command to push the table view controller onto the navigation controller

[self.navigationController pushViewController:<the instance you created of your table view> animated:YES];

You have to make sure to import the table view controller class into the 1st view controller.

Hope this helps smile.gif
Ilyace
QUOTE(alloutmacstoday @ Aug 4 2008, 09:17 PM) *
Well for starters, you don't want to rely on IB for this kind of stuff.

Make a new class that subclasses UITableViewController. It will automatically set itself as data source and delegate. Then, you take the methods from the view controller (the ones you used because it was delegate and data source), and put them into the UITableViewController class. (You do have methods like numberOfRowsInSecton, etc, right?). Then, in the other view controller class (the 1st VC), you have a void action called like push, then when invoked, calls the command to push the table view controller onto the navigation controller

[self.navigationController pushViewController:<the instance you created of your table view> animated:YES];

You have to make sure to import the table view controller class into the 1st view controller.

Hope this helps smile.gif


Thanks I'll try this out. I really don't get what was wrong in IB tho, I had set the view controller's view to the table view, etc...I did the same with the view controller that is already included in the template I'm using and It worked.
alloutmacstoday
Yeah, it should work, but I have had problems with this as well. With the iPhone SDK, I try to use IB less and less, because it seems to have some issues.
Ilyace
QUOTE(alloutmacstoday @ Aug 4 2008, 11:27 PM) *
Yeah, it should work, but I have had problems with this as well. With the iPhone SDK, I try to use IB less and less, because it seems to have some issues.


Thank you soooo much!!! It worked YAY! lol I've been trying to get this to work in IB for like 3 days now, so thank you very much!
alloutmacstoday
your welcome smile.gif

glad I could help smile.gif
stroke
Using Interface Builder saved me about 1000 lines of code wink.gif
alloutmacstoday
IB does rock, but somethings don't like to work in it. It has saved me lots of time, sometimes though. So, I still love it smile.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.