 |
 |
|
 |
06-22-2009, 12:20 PM
|
#1 (permalink)
|
|
New Member
Join Date: Jun 2009
Posts: 10
|
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!
|
|
|
06-22-2009, 12:31 PM
|
#2 (permalink)
|
|
at this moment
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 870
|
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.
|
|
|
06-22-2009, 01:05 PM
|
#3 (permalink)
|
|
New Member
Join Date: Jun 2009
Posts: 10
|
Quote:
Originally Posted by jsd
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];
|
|
|
06-22-2009, 01:20 PM
|
#4 (permalink)
|
|
at this moment
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 870
|
just change the frames of the toolbar and the tableview so the toolbar is on the bottom and the tableview stops above it.
|
|
|
06-22-2009, 01:49 PM
|
#5 (permalink)
|
|
New Member
Join Date: Jun 2009
Posts: 10
|
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.
|
|
|
06-22-2009, 04:08 PM
|
#6 (permalink)
|
|
at this moment
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 870
|
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.
|
|
|
06-22-2009, 05:38 PM
|
#7 (permalink)
|
|
New Member
Join Date: Jun 2009
Posts: 10
|
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.
|
|
|
06-22-2009, 05:44 PM
|
#8 (permalink)
|
|
at this moment
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 870
|
yeah but what is self.view? if the controller is actually UITableViewController then that would be the problem.
|
|
|
06-22-2009, 06:05 PM
|
#9 (permalink)
|
|
New Member
Join Date: Jun 2009
Posts: 10
|
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?
|
|
|
06-22-2009, 06:42 PM
|
#10 (permalink)
|
|
New Member
Join Date: Jun 2009
Posts: 10
|
Quote:
Originally Posted by slybitz
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?
|
|
|
06-22-2009, 07:10 PM
|
#11 (permalink)
|
|
at this moment
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 870
|
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.
|
|
|
06-22-2009, 07:41 PM
|
#12 (permalink)
|
|
New Member
Join Date: Jun 2009
Posts: 10
|
Thanks for your help. I'll continue to mess around with it to see if I can get it.
|
|
|
01-04-2010, 04:43 PM
|
#13 (permalink)
|
|
Registered Member
Join Date: Dec 2009
Posts: 9
|
Quote:
Originally Posted by slybitz
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?
|
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» Advertisements |
» Online Users: 420 |
| 43 members and 377 guests |
| amit.wizkid, andrei_c, AppStoreMod, bensj, Bertrand21, BrianSlick, cje, Cooper_1988, CunningCat, develsolutions, Dorald, eJohnny, Findus, fredidf, georgeburns, Gi-lo, graph, Guit, HemiMG, james_womack, jaume, javaconvert, leeus, Max, MiniRobinho, mr.pagu, noobAppDeveloper, Nuncha, Panajev, pion, Pwsoccer, rahulskh, Rudy, sayhong, seejaneworkit, Shlice Ideas, TheZimm, twerner, walkman2001, wilky94, yannickd60, _nivek |
| Most users ever online was 779, 05-11-2009 at 09:55 AM. |
» Stats |
Members: 24,301
Threads: 39,104
Posts: 171,438
Top Poster: smasher (2,575)
|
| Welcome to our newest member, alekssebasstrs |
|