He optado por usar un UITableViewController
sin una punta. Necesito una UIToolbar en la parte inferior con dos botones. ¿Cuál es la forma más simple de hacer eso?¿Cómo agregar una UIToolbar a UITableViewController programmatically?
P.S. Sé que puedo usar fácilmente un UIViewController
y agregar un UITableView
, pero quiero que las cosas se vean consistentes en toda la aplicación.
¿Alguien puede ayudar?
vi el siguiente ejemplo y no estoy seguro sobre su validez:
(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear: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 *infoButton = [[UIBarButtonItem alloc] initWithTitle:@"back"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(info_clicked:)];
[toolbar setItems:[NSArray arrayWithObjects:infoButton,nil]];
//Add the toolbar as a subview to the navigation controller.
[self.navigationController.view addSubview:toolbar];
[[self tableView] reloadData];
}
(void) info_clicked:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
[toolbar removeFromSuperview];
}
necesidad de señalar que la línea más importante aquí es [sizeToFit barra de herramientas]; sin él - se muestra la barra de herramientas, pero no se aceptan las interacciones del usuario –