When and where should I add a view to a UITableView's footer? - iphone

I am populating a UITableViewController's UITableView through code only. At the bottom of the table I wish to position a button that scrolls into view as the user scrolls to the bottom of the table.
When in the UITableViewController life cycle should I populate the table footer with a button? viewDidLoad?
p.s. I wish to avoid using section footers in the UITableView.

Yes, viewDidLoad is the correct place. It's not a stone-set rule though - I have change footer view in many different situations, such as after rotation in didRotateFromInterfaceOrientation.
Note that the view will be repositioned to location immediately below the last row, so if you want to provide a margin or centering for your button I suggest adding a plan UIVIew as footer, and then add your button(s) into that UIView.

Yes, put it in viewDidLoad. Here is some sample code.

You can just set the tableFooterView property of a UITableView to your button.

Related

View with uitableview, tabbar and more objects

I'm developing an app and I need a view with these elements:
- UITableView
- UITextField and UIButton
- TabBar
As you can guess, I am developing a chat, but when I put the elements in the .xib, I can't show de layer: UITextField and UIButton. If I put them without a view, they dont appear.
If I put a view under the table, and in that view I put the text and the button I get this error: http://pastebin.com/CKfxijz9 (I put the error there because it's to long)
Thanks in advance
There are some ways of dealing with that, depending on how it should behave. Some of them are:
Provide a table footer or header view that holds the button and
the text field.
Nest the table view into another view. The table
view and the view containing the button and text fielt are on the
same level within the view hierarchy. They are rather siblings than
sub- and superview to each other.
Use a UISlider instead of a table. (However, I personally would use the table.)
Here's an approach I've used in the past (not sure if it's best practice, but it works).
Add your button and textfield to a new view (let's call it, bottomView)
Add bottomView to the superview of your tableview
Set the frame of your bottom view so that it fits to the bottom of the screen (this will make it so your tableview will scroll, but keep your bottomView always attached to the bottom of your mainview)

Let tableview's last cell scroll to half way up the screen

I have a tableview with custom cells. Each cell has a UITextfield. When the last cell's textfield is clicked, the keyboard pops up and covers it and the table view won't scroll up any further. Is there a property of UITableview that can be set so that the last cell can scroll to half way up the screen?
Thanks in advance
There are a two ways to approach this (that I can think about off the top of my head):
You can use the tableFooterView property of UITableView to set an arbitrary, empty view to be about half the size of your table.
You can add empty cells to the bottom of your table
Both of these approaches will accomplish roughly the same thing, but using the tableFooterView property is probably your best bet.
see Making a UITableView scroll when text field is selected for a list of solution..
Also basing your view controller from UITableViewController (since you say its a table) will provide all this functionality automatically!

Adding a button in the bottom of a TableView

I'm trying to add a button on the bottom of a TableView, without any success.
The idea isn't to use the tableFooterView property, as that doesn't show the button in a fixed position.
My idea is more along the lines of the Facebook application's Notifications bar on the bottom.
I'm using Three20.
Any pointers on how I can achieve this?
Thanks
Just add button to the view below your tableview but ensure your table height is less than the position you are adding the button,this way your can scroll table above button & your button will always be visible
Just embed custom view over your tableview.i mean on the bottom of tableview.so the tableview will scroll and the view don't.
Add a UIView as the footerView and then add the UIButton to the UIView.

Can a UITableView (not UITableViewCell) have variable size?

I have a UIView (created in IB) with a grouped UITableView as a subview. Below this table view is a UIButton. The XIB containing the view will be loaded by a few different viewcontrollers, and so the contents of the table view can vary between one and four cells.
Here's what I want to achieve: when the view loads, the height of the tableview (tableView.frame.size.height) should be adjusted depending on the number of cells, and the button should be placed just beneath the table view.
Can this be done? Could it somehow be done if the view is created programmatically?
Thanks in advance
Edit: Pxl's suggestion was just what I was looking for. A while later, the need arose to have more than just a button below the table view - this was accomplished by creating a separate view containing everything I needed, and implementing the tableView:viewForFooterInSection: and tableView:heightForFooterInSection: functions.
A note for those of you trying to do the same thing: the tableview has to be programmatically created if you want different heights for the footers, or footers for only some of the sections. This is because the footer height set in IB will override the one returned from the tableView:heightForFooterInSection: function.
if there are only a handful of rows, may i suggest that you create a special UITableViewCell that contains just a button?
then make that button cell the bottom row of the last group all the time. make the group so that it will be unlabeled and appear as if the button is sitting at the bottom of your tableview. this way you won't have to muck around with recalculating the tableview's frame and redrawing it.
if the tableview will scroll due to there being many rows, then you'd be calculating the height of the tableview up to a set max (at which point the tableview will need to scroll to show more rows).
once you've determined the height of the tableview you'll need to display your rows, make a frame of the appropriate size, set the tableview's frame to it, position the button just under the tableview, and then redraw the view.
the layout and positioning in this case will need to be done programmatically.
UITableview is a subclass of UIView, so you can change its frame to suit your needs just like a UIView, and UITableView will manage drawing itself to whatever frame you give it.
Just use the methods UITableViewDataSource and UITableViewDelegate provides you.
height = [self tableView:numberOfRowsInSection]*[self tableView:heightForRowAtIndexPath:] + A_CONSTANT_FOR_HEADER_AND_FOOTER_HEIGHT
I agree with pxl that adding a cell with the button in it may be the easiest way to accomplish what you want.
Whether or not you do that, the table view's sizeToFit method should resize the view to (just) fit its contents. If that doesn't work, you can use numberOfSections and rectForSection: to build a loop that determines the height of the table's contents, and reset its frame manually. (And then position the button underneath.)

Problem in UITableView and UIScrollView

My table has more than 10 rows with 50 row height....so i can't select my last row....so i have set UIScrollView and add this table into UIScrollView.
Table display perfectly but which rows are displayed in UIScrollView, these are not selectable.
How can i get this row selecablt in UIScrollView. If anyone body know then pls tell me wha to do?
Thanks,
Haresh.
Putting a UITableView inside a UIScrollView won't work, beause UITableView is a UIScrollView. You're going to have to work out why UITableView won't scroll properly for you on its own.
Check how you initialize it and look at some of Apple's example UITableView code to see what is different.
It may be that your navigation bar, toolbar or some other control is hiding that last row. Check to make sure the tableview partly under another control.