How to place buttons above a UITableView (and not in the navigation bar)?

I am new to iphone programming. I'm currently studying uitableview. I need to create an application that has buttons above the table view (but not in the navigation bar), as in this application (last, support, ...): enter image description here

How is this achieved here, are the buttons part of the table header? Is it possible to call the function to redraw the tableview with the new data after clicking the button above the table. How it's done?

Thanks.

+4
source share
5 answers

Create a new view controller, but do not check the box for the UITableViewController subclass. In IB, drag the uiTableView onto the view and launch it about 44 pixels below the Nav line. Then drag the buttons into this space. Declare IBOutlet variables in your .h file and include them.

For the second part of your question: click the IBAction call button and call this method

[myTableView reloadData]; 
+2
source

The buttons can simply be placed on the green background image (in the example above) above the UITableView, i.e. your table view may begin below the green background image on which the buttons are located.

+1
source

You can do something similar in your init 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]; 
+1
source

If you do not want to scroll through these buttons with your table view, you can add them to your IB and add a table below them. Assign a tag to each button in IB. When a button is clicked, check the action (which you specified for the buttons) for the button tag and reload the table according to their tag.

If you want to scroll through the table, add them to indexPath.row == 0.

They are also buttons of type custom, and these magicians are set for them.

0
source

What you want is actually quite simple ...

You have a UITabBarController with a UINavigationController , which again is like a UIViewController , etc. how is rootcontroller? Then in your loadView / XIB, you simply create a custom UIView with any size, color, etc. Then you attach the UISegmentedControl to this view. And then you have a UITableView located at the bottom of the custom UIView . Its just a linear layout with a vertical orientation.

Then you will have a fixed positional view "above" the UITableView .

And you probably want to use a UIViewController for this if you are wondering if you can use a UITableView ...

0
source

Source: https://habr.com/ru/post/1347914/


All Articles