Scrollable all the way UITableView - iphone

I have this code linked to a button on a ViewController with a UITableView as subview:
-(IBAction)Action:(id)sender{
[tableView setContentSize:CGSizeMake(320, 1000)];
}
This makes tha tableView scrollable to the bottom so that I can use a couple of buttons I programatically added to the bottom. So far so good.
However, I want the tableView to be ok from the beginning, so I added the code inside viewDidLoad. Surprisingly, it doesn't work at all.
Could somebody give me a hand?
thanks!

If your datasource methods are being fired after viewDidLoad, the tableView content size will be reset when it's loaded. You'll need to make sure you've called reloadData for the table before the code above. If you're using a UITableViewController, the order the methods are called is:
viewDidLoad
ViewWillAppear:
<your datasource methods>
ViewDidAppear:
However, if you want buttons at the end of table, you should put them in the tableFooterView. You can do this in interface builder easily by dragging a view to the bottom of the tableView. Or you can do it in code (in your viewDidLoad method, for example)
Per #Justin's answer... your question isn't very clear

I'm not sure what your trying to accomplish. If your trying to access button on the bottom of a tableView why not use a Tableview Footer.
And if your trying to just scroll to the bottom of the tableview there is a method for that as well.
Need more info

Related

Two UICollectionViews manager by one controller

I have a UIViewController that is embedded in a navigation controller. The navigation controller has a switcher with 2 items on it.
First item shows a UICollectionView with images, and the second UICollectionview needs to show an Image with some description text.
I have assigned the delegates in the ViewController for these two UICollectionViews to self.When the Viewloads, the first UICollectionView shows all the images. When I click on the second switcher item, none of the delegate methods like numberOfItemsInSection, cellForItemAtIndexPath gets triggered.
In viewDidLoad I hide the second UICollectionView and when the user hits the second switcher, I hide the first UICollectionView and unhide the second UICollectionView.
I cant figure out what is the issue. I tried using a [self.secondCV setNeedsDisplay] to trigger a redraw, but that dosent seem to work as well.
Anyone who has tried doing something similar or can explain what I might be doing wrong here ?
Thanks,
Abhishek

Add delegate to custom UITableView

I have a custom UITableView integrated in my ViewController, with more elements, and I tried to add to the UITableView a control to refresh its content, like twitter app. The problem is that I can't capture the scrolls of the tableview in the ViewController. If I set the delegate of the custom UITableView, then I can capture the scrolls but I get troubles with the custom table behavior.
So, I don't know what it's better, either find the way to add the delegate for scrolls without override anything or find a way to add the control to refresh the table from the ViewController, not from the UITableView class.
The case with more details is:
A library for the custom UITableView. It's used to draw a conversation like the message app. So I just pass the information to the table and the table draw it. I don't do anything more, not delegate, nothing, just add the table to my ViewController.
I put the methods of the scroll's delegate in my ViewController, and, when I do scroll in the table, I don't get anything(the app doesn't enter in the scroll's delegate methods). If I set the table's delegate to self, the scroll works but I get some random problems from the table( I don't know how it's made the table), so I have to discard this option(set the delegate).
Thanks in advance
Try using the UIRefreshControl object. You define this object in the viewController in the viewDidLoad method and add the target to your tableView when it's value changes, here is an example:
self.refreshControl = [[UIRefreshControl alloc] init];
[self.refreshControl addTarget:self.tableView action:#selector(reloadData) forControlEvents:UIControlEventValueChanged];
Your viewController needs to be a UITableViewController however. To initiate and end the refresh use the methods:
[self.refreshControl beginRefreshing];
[self.refreshControl endRefreshing];

How can I place a UITableView on a UIViewController programmatically so that it doesn't take up the whole view?

I want to have a ViewController that has a table view on the top half of the screen, and a button under it. I'm assuming there's a simple way to do this. Every way I have tried so far ends up in the bottom half of the view being inaccessible.
The trick is that you cannot use a subclass of UITableViewController. You need to enable the datasource and delegate protocols explicitly in a UIViewController.
#interface MyController : UIViewController <UITableViewDatasource, UITableViewDelegate>
// variables and properties
#end
Don't forget to assign self as delegate and datasource of your tableview.
Now you can just put the table view anywhere by giving it an appropriate frame and you can also put a button at the bottom.
Hint: the standard way to "put a button at the bottom" is to use a UIToolBar. With that you could use the normal table view controller without having to worry about the protocols. But your approach is also feasible.
Well, you could have put a sample image to get the clear idea. but AFAI understood, i try to give the answer accordingly :
You can set the frame especially height of TableView just half the size of the height of your UIViewController.
Then rest of the space of UIViewCobtroller you can create another view where you can place your button as you have already done so far.
You can add the button in your UITableView's footer section.

Adding UITableView to subview when searchbar is being edited

I have a MKMapView with annotations on it and it works fine. I have a search bar as part of my navigation bar. When a user clicks on the search bar field I wanted to bring up a UITableView in code. I create a UITableView in the initialisation and want to add it to the sub view when - (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar; gets called.
This all works fine but im trying to add it using [self.view addSubview:tableView] and nothing shows up. I've only ever made table views using UITableViewController so I'm a bit lost.
Thanks
I'd suggest creating a UITableViewController to control it, and then using presentModalViewController:animated: to show the tableview.
This was actually correct. I was just initialising it wrong not setting the bounds for it.

How to adding custom views around a UITableView?

Is there a way to add custom views above and below a UITableView?
I'd like to have a custom header and a custom back button in the footer. What would be the best to do this?
I've started by subclassing UITableViewController and tried resizing the UITableView. In vain.
Tried adding a new main view to UITableViewController and adding the UITableView as a subview to it. Result: table view won't appear at all.
Tried adding the back button as a subview to the table view, but it will get scrolled this way.
Now I guess it would be the best to somehow replace the "original" header/footer, but is that possible?
Edit: Solved!
Using this tutorial, I've managed to add the required header and footer to the view using the Interface Builder.
Shouldn't the UITableView's tableHeaderView and tableFooterView properties do just what you want?
Ultimately I couldn't achieve what I wanted by code, but as noted in the edit of the original question, I was able to it using Interface Builder with the help of this tutorial.