How to place a button below a UITableView managed by UITableViewController - ios

I have a screen with a table view managed by a controller based on UITableViewController. I would now like to affix a button to the bottom of the screen so that it does not scroll along with the table view cells.
Replacing the UITableViewController with a plain UIViewController is not an option, as I want to include a UIRefreshControl. From what I have read, using a UIRefreshControl without a UITableViewController is currently not possible without resorting to any hacks / relying on undocumented behaviour.
I tried using a UIToolbar provided by the navigation controller which my table view controller is contained in, but there are two problems with that approach:
I only want the toolbar with the button to be present in the top level table view. However, I have not found an elegant way to only show the toolbar for the top level table view. I want the toolbar to animate out of the screen to the left together with the table view when I drill down.
I have not found a way to increase the height of the toolbar. Would I have to put the button in a dummy UIView?
This is approximately what I am aiming for:
http://pic.rockmynews.com/img/free-iphone-app.png
Another idea is using a container view controller containing the button at the bottom and the table view controller above it as its child view controller. But that seems a lot of work for something this simple.
So what is the best way to do this? Any recommendations?

Create the UIView container view. But also create a UIViewController subclass to manage the container. Then, add your existing table view controller as a child view controller and add the table view as a subview. Now you can control all of the subviews and positions while still having automatic refresh control operation.

Just use
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
and return a UIView for the desired button. and
tableView:heightForFooterInSection
and return the footer height

If you aren't willing to use a container view controller, you could use a third-party pull to refresh control like https://github.com/samvermette/SVPullToRefresh instead. This has the added benefit of being backwards compatible with iOS 5, if you want to support it.

You can use a UITableViewController. Just override viewDidLoad and then resize the tableView to make room for your extra view and then add your view programmatically. Make sure to set the right resizing mask so that things look correct on different screen sizes. (Easily tested in the Simulator by trying it out on the iPhone4 and iPhone5)

Related

Table View is taking interaction when a view of same bounds is added above that in OS X

My app contains a Table View which is scrolling and taking events properly. But after that I have to show a custom pop up to screen for that I have added a full view over the Table View. But after adding the view over Table View, Table view is still scrolling and taking events.
Please help if anyone have knowledge about that...
Thanks
The best way to achieve this is to add a blur view into your nib file first. This is better approach as the user is made aware of the current enabled object.
Once you add the blur view over the tableView you are showing, add your custom pop-over. This would maintain a clear demarcation between the two views and you would be able to achieve the functionality you want as the touches won't flow to your tableView.
Follow below steps may work:
Add overlay view on screen to show data on top of table view
make TableView Disbaled as soon as u add view on it.

Implementing A Mail app-like User Interface

I am trying to implement a user interface that is similar to the iPhone's Mail app.
The main screen displays a table. From the table the user can select a cell, at which point the next screen is launched. At the bottom, there is a bar showing a short text and an icon.
The second screen displays the details of the cell. It will also be a table display. The bottom bar shows icons associated to this screen.
What kind of layouts do I use to implement this in Xcode?
1. Do I use a View controller, add a View and embed a TableView and a Toolbar inside that view?
2. Do I use a Table View Controller and add a Table View inside it and use the bottom tool bar that comes with the table view?
In the Table View Programming Guide for iOS, under 'Recommendations for Creating and Configuring Table Views,' it says 'Use an instance of a subclass of UITableViewController to create and manage a table view.' When I use this, the bottom bar can only be fixed or disappear when going back and forth between two screens via segue. That makes me wonder whether I should just use a View controller which is against the recommendation.
Use a UIViewController
Why?
If you are going to display more than a tableView then it is recommended to use a UIViewController for the storyboard.
UIViewController are much more flexible. I guess your confusion comes from the following documentation line:
Use an instance of a subclass of UITableViewController to create and
manage a table view
This does not mean you must to drag and drop a UITableViewController on the storyboard. It means your class need to inherit from UITableViewController or at least implement the deleguate and datasource methods.
You would use UITableViewController only and only if you need to display a tableView.

How to add centered UIActivityIndicator for UICollectionView when using UICollectionViewController?

I'v never used UITableViewControllers or UICollectionViewControllers, because you can have the same functionality by using UIViewController with its root UIView, then adding UITableView in xib or storyboard and assigning its delegate and datasource. And I also was able to put activity indicator inside the center of root UIView.
Now the things get a little bit complicated when using UICollectionViewController where its root view is UICollectionView. I need to update some code of other guys and they put activity indicator inside UICollectionView (in storyboard). The problem is this activity indicator gets hidden when cells are reused because activity indicator view is the most bottom one. I was unable to change visibility priority storyboard and also this code in view didLoad is not working:
[self.itemsCollectionView bringSubviewToFront:self.activityIndicator];
Because labels, images and etc. views of collection view cell are placed later, during collectionView:cellForItemAtIndexPath:. I could try to call bringSubviewToFront: in collectionView:cellForItemAtIndexPath: but that would be a wrong decision. Any ideas how to achieve this when using UITableViewControllers or UICollectionViewControllers?
IMHO the only reason to use UITableViewControllers or UICollectionViewControllers is because static cells are not shown storyboards when designing layout.
UPDATE It appears iOS wraps UICollectionView inside UICollectionViewControllerWrapperView. Tried to add activity to this wrapper view in viewWillAppear:
[self.itemsCollectionView.superview addSubview:self.activityIndicator];
But with no luck - activity indicator is still is below the cells.
I'v ended in refactoring existing UICollectionViewController in storyboards: I'v opened storyboard xml file with TextEdit, searched for the screen and changed its type from collectionViewController to viewController because was unable to find another way how to change the type of controller, though I hope there will appear some more elegant way for that in the nearest future. Then, I'v wrapped collectionView inside root view and placed activityIndicator inside this view. It's proven classical approach that works like a charm.

Can't change the size of a TableView in Interface Builder

I'm trying to change the size of a tableView I have in interface builder and can't seem to. When I first started the app I could drag it around and stretch the sides but all of a sudden I can't adjust it. I tried to delete my tableView and add a new one but the same thing happened. Thanks in advance. Here's what I see when I try to change the size:
if your using a UIViewController you can drag and drop a tableView and can place in a custom position you want. but if your using a UITableViewController you cant move the tableView to your custom position. if you want to do it in UITableViewController you can do like below
if you want your tableView content should show from a point, that you want you can do this way,
[self.tableView setContentInset:UIEdgeInsetsMake(100,0,0,0)];
else if you want set your tableView to a frame in UITableViewController you do this way,
- (void) viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
self.tableView.frame = CGRectMake(0,100,320,300);
}
hope this will help you.
What kind of view controller are you using to manage your table view? Since you show "prototype cells", I'm guessing it's a UITableViewController. Those are built to fill the entire screen with a single table view (which has always annoyed me.)
Starting with iOS 6, though, you can create a "container" view in another view controler, and then drag an embed segue from your container view onto the table view controller. That does all the housekeeping to make the table view controller a child view controller of the other one, and then you can make it whatever size you want.
If you don't want to use a UITableViewController as a child of another view controller, you can use a regular view controller and wire up the data source and delegate methods yourself. However, things like static table views and prototype cells don't work then.
Hopefully this helps someone still coming across this problem. What I did was make sure the UIViewController had a UIView as its direct child, then dragged the UITableView as a child of the UIView, this allowed me to resize the UITableView.

Floating button over UItableview using storyboards

I have made a table view using prototype cells on tableviewcontroller from storyboards.
I want a floating button over that uitableview. (button won't scroll with the tableview).
While searching for a solution..I found out that it is possible by adding button to the superview (in that case Uiviewcontroller subclasses Uitableview).
Can any one tell me how to do that 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 <UITableViewDataSource,UITableViewDelegate> to your view controller interface.
If you must do it using Storyboards and not in code, then you need to use a UIViewController and not a UITableViewController.
Add the UITableView and make it full screen - link up its Delegate and DataSource to the UIViewController and adhere to the two protocols in the .h file of your UIViewController.
When adding the button, drag it into the view hierarchy in the "Document Outline" sidebar, and not by dragging it onto the UITableView. Be careful if you're ever dragging the button around the view because if you drag and drop it on top of the UITableView then it will become a subview of the UITableView. If you want to move it around you'll need to select it and then use the arrow keys.
Anyway, apart from that it should all be very easy - add your constraints to keep it in the right place and you should be able to use the button as normal.

Resources