How to put a UITableView in the center of a UIView - objective-c

I am just trying to create a simple Twitter app. Currently I have a UITableViewController that shows everyones name and pictures in the cells. When the cell is clicked, it pushes a new UIViewController that has a UIImageView and a UITableView. Their name is displayed as the title on the Navigation Bar and their picture is shown in the UIImageView. I have an NSArray that has a list of their statuses that i am trying to add to the UITableView. What is the easiest way to do this? thank you

You need to implement, at a minimum, the UITableViewDataSource protocol, and set the implementing object ('self' is perfectly fine if you're implementing it from the view controller you created it in) to the 'dataSource' property of your UITableView.
This protocol will let your class say how many rows it has (which should be the size of your array), then for the tableView:cellForRowAtIndexPath: you can populate the content of each tweet (again, relating the IndexPath row against your array).

Related

How to update UITableView after adding/ updating data

I am newbie for iPhone application. For storing data, I am following this tutorial.
I understand how to save data and retrieve the same.
What I am wanted to do is instead of another UITableViewController (first screen in storyboard, where we have list), I will drag a UITableView and show list of items there instead of showing in another screen.
Any idea/ suggestion how to get this done?
Any hints would be greatfull.
What I feel is, I would need to add UITableView. Add delegate and dataSource method on it and add a method where I will have all data shown in UITableView.
Edit 1
What I want is ONLY ONE SCREEN. In the link that I have provided, it is second screen.
That should work fine. But make sure you also have done a
[tableview reloadData];
after you've changed the data in your table view data source delegate.
What I am wanted to do is instead of another UITableViewController (first screen in storyboard, where we have list), I will drag a UITableView and show list of items there instead of showing in another screen.
Why you want to do this way?
UX will not be at best.
What I feel is, I would need to add UITableView. Add delegate and dataSource method on it and add a method where I will have all data shown in UITableView.
Even if you want to do, yes you need to set delegate and datasource methods.

Combined UITableView with other elements - how to create and use the view?

Ive a project close to doing everything I need it to do. Its got a Main page which has four buttons that allow you to choose an option. Then a tableview page is launched from those options and displays a parsed XML feed from a website. You can then select one of the options in the table to see a detail view of the item, enquire about it, etc.
My problem is I need to add more elements to the TableViewController page, other than the tableview itself. I want a customized back button (not the navigation controller standard) plus some labels, images, etc.
In the TableViewController xib, the tableview itself fills the page. I cant resize it to add more elements above it. I can add a 'view' window seemingly above the tableview and put things in it. But it seems to add the view to the tableview. This means that when I scroll the table, the other elements like new back button, scroll away as part of the table.
So I'm led to wonder whether I need this page not to be a tableviewcontroller, but a viewcontroller, with a tableview inside it, as well as my other view with buttons, etc. Is that the right way to go? But if thats the case, then how do I instantiate the tableviewcontroller within code? Because my page will not be of that type anymore - it will be just a viewcontroller. But in code Im making a tableviewcontroller .. slightly scared by that route tbh.
Any illumination on this would be much appreciated, as various searches have left me none the wiser. Thanks.
To customize it, this is the way to go:
Change your class to be a view controller instead, which implements the TableViewDelegate and TableViewData Source protocols.
In the view didLoad of you controller, create the table view, set its delegate, data source, and any other properties you wish and add it as a subview to your view.
tableView = [[[UITableView alloc] init] autorelease];
tableView.delegate = self;
tableView.dataSource = self;
// .. Other customization
[self.view addSubview:tableView];
I suggest doing this programatically rather than IB.
Instead of a UITableViewController, you want a UIViewController that has an IBOutlet UITableView. Drag and drop a UITableView component from Storyboard and hook it up, and position it as needed on the screen. This UIViewController should implement the UITableViewDelegate and UITableViewDataSource methods.
Edit: Remember that a UITableViewController is just a subclass of UIViewController so you don't really have to get rid of all your code. :) You only need to make minor tweaks to your header and main file, and change the Storyboard to be a UIViewController instead of UITableViewController as I mentioned above.

Add other objects to iOS 5 storyboard after tableview

I have a simple iOS 5 storyboard that contains a tableview controller scene. However, the table UI takes up 100% of the real estate and I am unable to add any additional objects such as a title bar. Any object that I drag to the scene will try to size correctly and what-not but as soon as I let go it will not add the object. What am I doing wrong?
If all you want is a title bar, then it looks like you want to embed your table view controller in a navigation controller. You can do this by selecting your table view controller and using the Editor: Embed In: Navigation Controller menu command. Once you do this, you should have a navigation bar, and you can double click it to edit the title.
If you need arbitrary UI elements along with your table view, then I think you need to use a plain UIViewController scene instead of a UITableViewController, and manually drag a UITableView into the scene. Your view controller would not subclass UITableViewController, instead it would subclass UIViewController and implement the UITableViewControllerDelegate and UITableViewControllerDataSource protocols. Also, you would need to manually wire up the delegate and dataSource outlets by ctrl-dragging from the table view to your view controller in interface builder, and your view controller would need a custom tableView outlet that points to the UITableView and is correctly wired up in IB. Perhaps there is a simpler approach than this though, if someone has a better suggestion that would be great to hear.

Re-use tableview from different controller: how to split didSelectRowAtIndexPath behaviour?

I'm currently working on my Favorites implementation. In the end, it should work the same as the favorites features in the Phone book on the iPhone.
I've the following set-up (besides other controllers and classes):
TabBarController (named mainTabBarController)
NavigationController with a Tableview (let's call it listNavController)
ViewController with some components for displaying row details (named detailViewController)
NavigationController with a TableView for favorite records (named favoritesNavController)
From the favoritesNavController, I want to select a row (from listNavController) so I can add a new entry to my Favorites tableview.
So, I decided to re-use my listNavController because it has all the functionality I need. Like searching, index, etc.
I've managed to show the listNavController from the mainTabBarController. So no problem here. When I select a row from the listNavController, it displays my detailViewController for that row. Of course, this was expected because that's in didSelectRowAtIndexPath in listNavController.
But, when I launch a listNavController from my favoritesNavController with the help of presentModelViewController, it still shows the detailViewController when selecting a row.
In this case, I want to return the selected row to my favoritesNavController. Then I can add it to my Favorite's list.
So, how do I differentiate this behaviour in code ? Should I use protocols, delegation, etc. ?
Any tips ?
With regards,
Rutger
It turned out that I was looking in the wrong direction.
The solution to the posted question is as follows:
I created a subclass of my listNavController and overrided the didSelectRowAtIndexPath method. Next I presented this new view controller with a navigation controller as a modal view (presentModalViewController).
Finally I set the delegate and a protocol for the subclassed view controller to the initiating class. This way I can present and dismiss the subclassed view controller from the same controller. A much more clean and MVC way to go!

UITableView that links Cell to UIWebView NSURLRequest

My question seems simple enough and yet I have not been able to find an example to follow.
I have a UITableView with a list of courses that I want to link to their respective URLs.
There are 21 courses in the list and when the user scrolls the list, they select a course that then should link them to the web page (with a "back" button to return to the list).
I've found examples to link the URL directly from a button but not from a UITableView list.
How can you link the Cell in the TableView list to the NSURL Request to then load the web page?
Anyone with an answer or a link to a tutorial, would be very appreciated.
Check the delegate methods for UITableView:
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UITableViewDelegate_Protocol/Reference/Reference.html
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
In your case you probably want to push another viewcontroller with a webview when the user taps a cell so you can allow the user to go back to the uitableview when he/she is done.
Make an data object called Link with two instance variables, the URLRequest object and a string that you want for your table cell to display.
When you set up your 21 objects, make 21 Link objects and store them in an array.
In your tableView:cellForRowAtIndexPath: method you will setup your row with the linkInsance.cellName value.
In your tableView:didSelectRowAtIndexPath: you will get the linkInstance.URLRequest and execute it.
You will get the link instances by getting an object by index in the array with the indexPath.row.
Use the standard "Navigation based application" template so that you've got a navigation controller in place. By default it is set up to use a table view controller as its root view controller, so it's a good starting point for you.
Now create a custom view controller subclass that embeds a UIWebView. Remember to create an IBOutlet for the webview and hook it up in Interface Builder. While you are in Interface Builder, select the main view and tell it you want a navigation bar at the top. Give your view controller an NSURL property too. In the loadView method for this class, tell the UIWebView to load that URL.
Now go back to the table view controller's delegate. In the tableView:didSelectRowAtIndexPath: method, create an autoreleased instance of your custom view controller. Assign the appropriate URL to the NSURL property that you just set up, then push it onto the navigation stack with [self.navigationController pushViewController:isAnimated:].