Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kingthong

macrumors member
Original poster
Sep 20, 2010
62
0
Somewhere but not here.
This might be a very simple procedure. i tried googling it but somehow couldnt find the right combination of keywords i guess.

anyway. i have a tab view controller that i run from my MainWindow.xib to switch between 4 screens. Now i have a separate button that opens a new viewcontroller thats not part of the 4 screens of the tab view controller.

My simple question is how do i(say, using a back button) get back Mainwindow.xib after i have opened the viewcontroller.

i tried

Code:
[self.view removeFromSuperview];
and
Code:
[self.view release]

but it doesn't work. Hope i've explained my problem properly.
 
It depends on how you have displayed the new view controller. The simplest option is to use a navigation controller that will automatically provide you with the back button which will pop the new view controller off the stack and return you to the preview controller (in this case your main view). The documentation has a lot of detail on this.
 
Code:
-(IBAction) loadAddView{
 Tasklist *tasklistView = [[Tasklist alloc] initWithNibName: @"Tasklist" bundle: [NSBundle mainBundle]]
[self presentModalViewController:tasklistView animated:YES];
}
;

this is my code to load the Tasklist.xib. I need a back button to revert back to this page.

Will go through the documentation as you suggested.
 
You have chosen to use a modal view controller instead of a navigation stack: it is now your responsibility to provide the back button and hook that up to an action that will dismiss the modal view controller.
 
You have chosen to use a modal view controller instead of a navigation stack: it is now your responsibility to provide the back button and hook that up to an action that will dismiss the modal view controller.

cool. Pardon my ignorance, but how do i do that?

If it were any other viewcontroller, i coulda used the
Code:
PageViewController *pageView = [PageViewController alloc] initWithNibName: @"PageViewController" bundle: [NSBundle mainBundle]];
[self.view addSubview: pageView.view]

or
Code:
PageViewController *pageView = [PageViewController alloc] initWithNibName: @"PageViewController" bundle: [NSBundle mainBundle]];
[self presentModalViewController:pageView animated:YES]

(i'm not sure if i understand what the diff between the two is)

But since, i've to revert back to MainWindow, i can't instantiate that and add it as a subview.
 
(i'm not sure if i understand what the diff between the two is)

Then you need to stop writing code until you do. Neither method you suggested returns you to an existing view controller. Both create new view controllers. One inserts the new view controllers view into the existing view controllers view hierarchy. The other displays the new view controller modally. Neither are a good idea (you will run out of memory if you keep creating new view controllers when you want to return to an existing one).

You need to go to the developer website, read and understand the documentation. I would recommend all of this, this and this as an absolute minimum. Don't be tempted to skip this: your grasp of the basic fundamentals of the iPhone view system is completely lacking.
 
Normally, you don't even mess around with MainWindow.xib. You provide other views / viewControllers. Even if you create a simple View-based Application, you'll notice that it's created another .xib that's set up to show the main content.
 
Thanks guys. admittedly i don't have a complete knowledge of this yet. But i was asked to work on a small assignment and hence the hurry to get it done.

As for why i was editing MainWindow.xib, i was(blindly) following the examples in the Apress Beginning IPhone Dev book.

Thanks for the help again. there's a good chance that i'll put up more queries here!
 
How have you modified MainWindow.xib that you want to go back to it? Maybe explain your view hierarchy / flow, so we can better suggest what you can try to do.
 
i'll try and do my best here.

I'm developing a simple task manager app for practice purposes. It accepts task name and date.
Now i opened MainWindow.xib and added a tab bar controller with 3 buttons for 'Today', 'This week' and 'This Month'. Each of these has a separate view controller which loads on clicking in the tab bar. all well and good there.

Now i have a separate button for AddTask which opens a new view by using the addSubView method. Hence i need a back button that goes back to the previous page.
Apologies but i'm very new to the language and i'm still getting the hang of it.
 
Now i have a separate button for AddTask which opens a new view by using the addSubView method. Hence i need a back button that goes back to the previous page.
Apologies but i'm very new to the language and i'm still getting the hang of it.
Thanks for the explanation. That helped. You should take some time and go through the View Controller Programming Guide (robbieduncan already linked to it) so that the concepts we discuss make sense. But, to me, instead of using addSubview: to present an entire new view, you would be better served presenting it modally.
 
okay i'll do that. if i may ask you a question.
Say you were designing the same program, how'd you go about it? i'm thinking of one rootController that has contains the TabBarController, one TableViewController and 3 instances of it for Daily, Weeky and Monthly?

Thanks dejo and robbieduncan for the advice. back to the drawing board for me but thanks again. You guys are really helpfull!
 
I'd probably use a UINavigationController as my root view controller. I'd put a UITabViewController as the navigation controllers root. Then when I want to drill down from the UITableView in any tab to a single task (detail view) I can just push that view controller onto the navigation stack.

If you don't want the title that comes with a UINavigationController on the "main" screen (the one with the UITabViewContoller) then it can easily be hidden and only shown when you drill down (so you have the task title on the detail view with a back button to take you back to the UITableView)
 
Thanks robbieduncan. I'll refer this thread in the future. right now going through all that heavy apple documentation!

Also, one more question. The 3 tabs in my TabBar- Today, This Week and This Month will basically perform the same operation, which is list out a few tasks. The only difference will be in what each page is listing out. Hence can i just write the one class and have instances of it for each of the 3 tabs? The difference would be the data i am providing it to print. this type of method is used in java i know...
 
Also, one more question. The 3 tabs in my TabBar- Today, This Week and This Month will basically perform the same operation, which is list out a few tasks. The only difference will be in what each page is listing out. Hence can i just write the one class and have instances of it for each of the 3 tabs? The difference would be the data i am providing it to print. this type of method is used in java i know...

Yes. That's the approach I use with the two apps in my sigs: they both display lists of data. I have one class that can display a list with all the functionality I want and just use different data sources to feed the view controllers with data.
 
cool. is there anywhere i can get sourcecode for a program like this? i'd like to see how its done. i'll get a grasp of things faster than reading the very dense apple documentation!
 
cool. is there anywhere i can get sourcecode for a program like this? i'd like to see how its done. i'll get a grasp of things faster than reading the very dense apple documentation!

As I always say reading the source code will not teach you anything (apart from perhaps the authors bad habits). Unless you are forced to think about it yourself you'll just copy and paste without any understanding.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.