I am new to iphone programming. I am learning uitableview at the moment. I need to create an app that has buttons above table view (but not in the navigation bar) like in this app (recent, support, ...):
How is this achieved here, are buttons part of table's header? Is it possible to call a function to redraw tableview with new data afte开发者_Python百科r someone presses button above tableview. How is it done?
Thank you.
Create a new view controller, but don't check the box for UITableViewController subclass. In IB, drag a uiTableView onto the view and make it start about 44 pixels below the Nav Bar. Then drag buttons into that space. Declare your IBOutlet variables in your .h file, and hook them up.
For the second part of your question: have the button call an IBAction, and have that method call
[myTableView reloadData];
The buttons can just be placed on a green background image (in the above case) above the UITableView i.e. your tableview can start below the green background imageview on which the buttons are placed.
You can do something like this in your init
method, or loadView
or wherever you prefer:
UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Recent", @"Support", @"Around here", nil]];
segment.segmentedControlStyle = UISegmentedControlStyleBar;
self.tableView.tableHeaderView = segment;
[segment release];
If you don't want to scroll these Buttons with your table view then you can add them in your IB and add your table view below them. Assign a tag to each button in IB. When a button is clicked then check in your action (that you have specified for buttons) for button tag and reload your table according to their tag.
If you want to scroll them with table then add them at indexPath.row == 0.
And also these are buttons with type custom and and these mages are set to them.
What you want is actually pretty simple...
You have a UITabBarController
with a UINavigationController
, which again as a UIViewController
etc. as a rootcontroller right? Then in your loadView/XIB you will just make a custom UIView
with whatever size, color etc. Then you attach a UISegmentedControl
at this view. And you then have your UITableView
positioned to the bottom of the custom UIView
. Its just a linear layout with a vertical orientation.
Then you would have a fixed positioned view "above" the UITableView
.
And you probably want to use UIViewController for this, if you wonder if you could use UITableView...
精彩评论