Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-22-2009, 12:20 PM   #1 (permalink)
New Member
 
Join Date: Jun 2009
Posts: 10
Default hide/remove toolbar

I have two forms that interact with each other. view1 (let's call it) has a form that a user fills out and when that user is done filling out the form he/she hits a "continue" button which opens up view2. On view2 I've create a toolbar on the bottom of the view with some basic buttons that perform various tasks related to view2. After initializing, adding buttons, etc... to the toolbar I've added the toolbar to my view like so:

Code:
	
//Add the toolbar as a subview to the navigation controller.
[self.navigationController.view addSubview:toolbar];
On view2 there is also a navigation bar at the top that has a button allowing the user to go back to view1. My problem is that when the user goes back to view1 from view2 I can't get the toolbar from view2 to go away. I.e., the toolbar still shows on view1 when it should be hidden. When the button to go back to view1 is clicked can't I just set toolbar.hidden=TRUE; in view2? Where would I put that piece of code? This seems really easy and I've gone through a lot of tutorials/forums/examples but I just can't find the answer. Extreme newbie here... thanks for your patience and help!
slybitz is offline   Reply With Quote
Old 06-22-2009, 12:31 PM   #2 (permalink)
jsd
at this moment
 
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 870
Default

You added the toolbar to the navigation view so of course it's going to show on all navigation controller owned views from then on. Add it to view2's view instead and you should be good to go.
jsd is offline   Reply With Quote
Old 06-22-2009, 01:05 PM   #3 (permalink)
New Member
 
Join Date: Jun 2009
Posts: 10
Default

Quote:
Originally Posted by jsd View Post
You added the toolbar to the navigation view so of course it's going to show on all navigation controller owned views from then on. Add it to view2's view instead and you should be good to go.
Thanks JSD. I changed it to: [self.view addSubview:toolbar]; which works but I still have an issue... How do I set the location of the toolbar to be static like it was when it was on the navigation controller where it is always visible and static at the bottom of the screen/view even if the view2's height is larger than what is on the screen? Right now, my toolbar is located way down past the end of the screen and I have to scroll down to see it. I can change the rootViewHeight to move it but then as the user scrolls on the tableview the toolbar also moves.

Code:
	//Initialize the toolbar
	toolbar = [[UIToolbar alloc] init];
	toolbar.barStyle = UIBarStyleDefault;
	
	//Set the toolbar to fit the width of the app.
	[toolbar sizeToFit];
	
	//Caclulate the height of the toolbar
	CGFloat toolbarHeight = [toolbar frame].size.height;
	
	//Get the bounds of the parent view
	CGRect rootViewBounds = self.parentViewController.view.bounds;
	
	//Get the height of the parent view.
	CGFloat rootViewHeight = CGRectGetHeight(rootViewBounds);
	
	//Get the width of the parent view,
	CGFloat rootViewWidth = CGRectGetWidth(rootViewBounds);
	
	//Create a rectangle for the toolbar
	CGRect rectArea = CGRectMake(0, rootViewHeight - toolbarHeight, rootViewWidth, toolbarHeight);
	
	//Reposition and resize the receiver
	[toolbar setFrame:rectArea];
	
	// create the array to hold the buttons, which then gets added to the toolbar
	NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:3];
	
	UIBarButtonItem* bi = [[UIBarButtonItem alloc]
						   initWithTitle:@"Submit" style:UIBarButtonItemStyleBordered target:self action:@selector(sign_clicked:)];
	bi.style = UIBarButtonItemStyleBordered;
	[buttons addObject:bi];
	[bi release];

	
	// stick the buttons in the toolbar
	[toolbar setItems:buttons animated:NO];
	
	[buttons release];
	
	//Add the toolbar as a subview to the navigation controller.
	[self.view addSubview:toolbar];
	
	//Reload the table view
	[self.tableView reloadData];
	
	[toolbar release];
slybitz is offline   Reply With Quote
Old 06-22-2009, 01:20 PM   #4 (permalink)
jsd
at this moment
 
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 870
Default

just change the frames of the toolbar and the tableview so the toolbar is on the bottom and the tableview stops above it.
jsd is offline   Reply With Quote
Old 06-22-2009, 01:49 PM   #5 (permalink)
New Member
 
Join Date: Jun 2009
Posts: 10
Default

I've tried changing the tableview's frame to be above the top of the toolbar with no luck. I've used interface builder and I've done it problematically with the below code. My toolbar is still on top of my tableview when the tableview is expanded past one full screen height. What am I doing wrong?

Code:
self.tableView.frame = CGRectMake(0, 0, 320, 200);
I forgot to mention, my tableview is dynamic and will not be a set size (size will change).

Last edited by slybitz; 06-22-2009 at 01:55 PM.
slybitz is offline   Reply With Quote
Old 06-22-2009, 04:08 PM   #6 (permalink)
jsd
at this moment
 
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 870
Default

hard to say without seeing it, but you mentioned that the toolbar is scrolling with the tableview. did you add the toolbar as a subview of the table perchance? don't do that.
jsd is offline   Reply With Quote
Old 06-22-2009, 05:38 PM   #7 (permalink)
New Member
 
Join Date: Jun 2009
Posts: 10
Default

No. I added it to the actual view.

Code:
[self.view addSubview:toolbar];
If I add the toolbar to the navigation controller like I originally had, it just doesn't make sense that when I load view1 I can't just hide the toolbar with something like "toolbar.hidden=TRUE;". I can remove it in view2 via this code but I'm just not sure how to remove it in view1's code. Seems like it should be really simple but being a newbie I don't get how to reference this in view1.
slybitz is offline   Reply With Quote
Old 06-22-2009, 05:44 PM   #8 (permalink)
jsd
at this moment
 
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 870
Default

yeah but what is self.view? if the controller is actually UITableViewController then that would be the problem.
jsd is offline   Reply With Quote
Old 06-22-2009, 06:05 PM   #9 (permalink)
New Member
 
Join Date: Jun 2009
Posts: 10
Default

I see what you are saying and it makes sense but self.view is a UIViewController. So there's no view exit event I can attach toolbar.hidden=TRUE; to?
slybitz is offline   Reply With Quote
Old 06-22-2009, 06:42 PM   #10 (permalink)
New Member
 
Join Date: Jun 2009
Posts: 10
Default

Quote:
Originally Posted by slybitz View Post
I see what you are saying and it makes sense but self.view is a UIViewController. So there's no view exit event I can attach toolbar.hidden=TRUE; to?
Never mind, I was looking a the wrong view. It is a UITableViewController. Sorry. If my controller is a UITableViewController is there any way to get around this or do I need to create a new view with a UIViewController controller?
slybitz is offline   Reply With Quote
Old 06-22-2009, 07:10 PM   #11 (permalink)
jsd
at this moment
 
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 870
Default

you could try attaching the toolbar to the tableview's superview or otherwise futzing with the view hierarchy. i'm not 100% sure what might or might not work to be honest.
jsd is offline   Reply With Quote
Old 06-22-2009, 07:41 PM   #12 (permalink)
New Member
 
Join Date: Jun 2009
Posts: 10
Default

Thanks for your help. I'll continue to mess around with it to see if I can get it.
slybitz is offline   Reply With Quote
Old 01-04-2010, 04:43 PM   #13 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 9
Default

Quote:
Originally Posted by slybitz View Post
Thanks for your help. I'll continue to mess around with it to see if I can get it.
Slybitz, I have the exact same problem going on.

Did you find a solution?
FnGreg7 is offline   Reply With Quote
Reply

Bookmarks

Tags
toolbar

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 24,301
Threads: 39,104
Posts: 171,438
Top Poster: smasher (2,575)
Welcome to our newest member, alekssebasstrs
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:24 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0