Create a button on top of UiTableView

泪湿孤枕 提交于 2019-12-10 21:32:50

问题


I am trying to understand how does Facebook Messenger create a button at the button of the screen which stays on top of the UITableView and follows the scrolling as well?

I want to implement the blue button on the bottom right. What should be my approach to achieve something like that?

Any push in the right direction will be highly appreciated.


回答1:


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)




回答2:


In your UIViewController subclass do this :

[self.view insertSubview:myButton aboveSubview:self.tableView];

NOTE : if your UIViewController is a UITableViewController, this code may not work, since UITableViewController place its table view as its root view, which make a lot of programmer stay away from it, because of the limitation that this imply.




回答3:


You can do this in your UITableViewController easily

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.window addSubView:myButton];

I tried this and it worked for me. Good luck! :)



来源:https://stackoverflow.com/questions/16049576/create-a-button-on-top-of-uitableview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!