मैं एक निब के बिना एक UITableViewController
उपयोग करने के लिए चुना है। मुझे दो बटनों के साथ नीचे एक UIToolbar की आवश्यकता है। ऐसा करने का सबसे आसान तरीका क्या है?कैसे एक UITableViewController प्रोग्राम के रूप में करने के लिए एक UIToolbar जोड़ने के लिए?
पीएस मुझे पता है कि मैं आसानी से एक UIViewController
का उपयोग करें और जोड़ने के एक UITableView
लेकिन मैं चीजों को एप्लिकेशन पर एक जैसी दिखना चाहते हैं कर सकते हैं।
किसी की मदद कर सकते हैं?
मैं निम्न उदाहरण देखा है और मैं इसकी वैधता पर यकीन नहीं है:
(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];
}
है कि सबसे महत्वपूर्ण लाइन यहाँ बात करने के लिए की आवश्यकता है [उपकरण पट्टी sizeToFit]; इसके बिना - टूलबार प्रदर्शित होता है, लेकिन किसी भी उपयोगकर्ता इंटरैक्शन को स्वीकार नहीं करता –