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

iphonejudy

macrumors 6502
Original poster
Sep 12, 2008
301
1
Hi,

I used the blow code for adding toolbar in run time ,But the toolbar is not added.


- (void)viewWillAppear:(BOOL)animated {
//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 a button
UIBarButtonItem *NewsButton = [[UIBarButtonItem alloc]
initWithTitle:mad:" News " style:UIBarButtonItemStyleBordered target:self action:mad:selector(News_clicked:)];




//Create a rectangle for the toolbar
//CGRect rectArea = CGRectMake(100, rootViewHeight - toolbarHeight, rootViewWidth, toolbarHeight);

//Reposition and resize the receiver
[toolbar setFrame:rectArea];


[toolbar setItems:[NSArray arrayWithObjects:NewsButton,nil]];
[self.view.window addSubview:toolbar];


//Add the toolbar as a subview to the navigation controller.

[self.view.window addSubview:toolbar];

//Reload the table view
[self.tableView reloadData];


}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.