How to Put Buttons Over Uitableview Which Won't Scroll With Table in Ios

How to put buttons over UITableView which won't scroll with table in iOS

One solution to this is to extend UIViewController instead of UITableViewController. You will need to add your own table view and set everything up. Then you can add your button's to the view controller's view instead of the table view.

Adding buttons to top and bottom of UITableView

I'm not sure exactly where you want your button, but UITableView have a

@property(nonatomic, retain) UIView *tableHeaderView

If you want it to be on the top of your tableView and scroll with it, just make the view you want and put it in that property.

Create a button on top of UiTableView

There are a few avenues to take when adding the overlay view:

  • As a subview of the wrapping UINavigationController, which means it won't scroll with the content of the table

  • As a section footer of a plain-style UITableView that has only 1 section

  • As a subview of the UITableView and use UIScrollViewDelegate's scrollViewDidScroll: to continuously update the view's frame as the user scroll's the table (which makes it appear to stay motionless)

floating UIButton with image on a UITableview

You can implement the scrollViewDidScroll delegate to change your floating button y origin while the user scroll the table, so that the button will float and stay at the same location.

There is a great example in WWDC 2011 session 125 that does exactly what you want.

In general, you need to save the original y origin of the button after you create it, or you can do it in viewDidLoad, then implement the scrollViewDidScroll and update the button frame.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGRect tableBounds = self.tableView.bounds;
CGRect floatingButtonFrame = self.floatingButton.frame;
floatingButtonFrame.origin.y = self.originalOrigin + tableBounds.origin.y;
self.floatingButton.frame = floatingButtonFrame;
}

Floating button over UItableview using storyboards

I think best thing you have to do is to create a UIViewController and add it a UITableView. Then you can add also the UIButton you want to the view controller's view. Don't forget to set the view controller to be the delegate and data source for your table view, and to add to your view controller interface.

iOS floating button over table view

Perhaps adding a toolbar with buttons at the bottom would be a better approach?



Related Topics



Leave a reply



Submit