Xcode 4. Adding tableView to tab bar application - uitableview

Ive created a new tab bar application in xcode 4 and it has generated a mainwindow.xib, firstView.xib, secondView.xib and viewController classes for each xib.
I would like to add a tableView to the firstView.xib, so i have added a UITableViewController class to the project and Xcode generated a new tableViewController.xib which displays a tableView.
How do i hook it up so the TableView is loaded into the firstView in xcode 4.
EDIT:
Ok, I've tried adding a tableViewController to the firstView.xib and setting its class name and nib properties to the name of my TableViewController class, but its not visible when the app runs.
Cheers

in firstView.h, add an IBOutlet which will represent the TableViewController
in firstView.xib, link the tableViewController to the corresponding File Owner IBOutlet
in firstView.m, in viewDidLoad method, initialize your tableViewController.

Here is a simple tutorial
http://www.techotopia.com/index.php/Creating_a_Simple_iOS_4_iPhone_Table_View_Application_(Xcode_4)

Related

How do I resolve "Static table views are only valid when embedded in UITableViewController instances" when creating an app?

I am an Objective-C beginner and I am going through the tutorial to create an IOS app using Apple developer articles.
https://developer.apple.com/library/ios/referencelibrary/GettingStarted/RoadMapiOS/SecondTutorial.html#//apple_ref/doc/uid/TP40011343-CH8-SW1
I have created an unwind segue and I have gotten stuck. I have gone through SO posts such as given below
StoryBoard issue in Xcode 6.1
Change a UIViewController to a UITableViewController inside a storyboard?
Want to create a cool static UI but : "Static table views are only valid..."
I tried to modify the story board source to use "tableViewController" instead of "viewController", but the storyboard won't open.
I am sure that there is an easy solution, but I don't know enough Objective-C or IOS development to know what it is, or how to implement it.
I have my controller implementing UITableViewController and my view as UITableView. I have attached the screenshot below.
and the error message:
My source for ToDoListTableViewController.h is given below:
#import <UIKit/UIKit.h>
#interface ToDoListTableViewController : UITableViewController
- (IBAction)unwindToList:(UIStoryboardSegue *)segue;
#end
and the implementation
#import "ToDoListTableViewController.h"
#interface ToDoListTableViewController ()
#end
#implementation ToDoListTableViewController
. . . Other methods
- (IBAction)unwindToList:(UIStoryboardSegue *)segue {
}
#end
Your picture is kind of small so it's a bit hard to tell what we're looking at. Plus your descriptions are a bit vague.
The deal is that in order to set up a table view as a static table view, it must be managed by a UITableViewController, not a regular UIViewController.
A UITableViewController is a special subclass of UIViewController. When you go to add a new scene to your storyboard, you go to the list of UI objects, find the UITableViewController, and drag one onto the storyboard.
An annoying thing about UITableViewController objects is that the ONLY thing they manage is a table view. You can't use them to set up labels, buttons, and other UI elements. Just a table view and nothing else.
You said:
'I tried to modify the story board source to use "tableViewController" instead of "viewController"...'
I have no idea what that means. What is a "story board source"? You don't "Modify the storyboard source", you drag a UITableViewController onto your storyboard.
Then you said "...but the storyboard won't open." I also don't know what that means. You're going to have to explain that.
Luckily, there is an easy solution to this.
What you want to do is to create a regular UIViewController to manage everything but the table view, and then put a "Container View" in that view controller and set up an "embed segue" that installs a UITableViewController inside that container view.
Here's how you do that:
Search in the list of UI elements on the right side for "container". Drag a container view onto your view controller where you want your table view to appear. Then drag a UITableViewController onto a blank space on your storyboard to create a new storyboard scene. Then control-drag from the container view in your first view controller onto the UITableViewController. This creates an embed segue, which causes the UITableViewController to be loaded as a child view controller with its view inside and sized to fit in the container view.
Now you can have a window that has both a table view managed by a UITableViewController AND other contents.
There are more details to setting this up that are beyond the scope of a SO post. I suggest you do some googling on container views and embed segues and try to find a tutorial on setting them up.

UITableView Troubles

I have created 3 tableview controllers from scratch on the main stroyboard in Xcode. I have desgined the rows etc.
Now when I create files, File-New to create the .h and .m files (Subclass UITableViewController), then I add the file as the Custom Class in the UITableView , the tableview does not show.
If I set the Custom Class as blank (default UITableViewController) it works fine.
Any ideas why it is blank and only the NAV bar is shown when I add the custom class to the table view controller.
thanks

Adding Outlets to View Controller via Table View Controller

I'm attempting to create an application for iOS, using Xamarin and storyboards. Within this, there shall be a button located in a TableViewController which will navigate the user.
To do this, I've used a Container, embedded to a TableViewController. However, my concern is I wish to add an Outlet from the button within the TableViewController to the ViewController header class - Yet it only allows me to try and add one to the 'UITableViewController.h' file.
What is causing this and how am I able to add the Outlet to the 'ViewController.h' file? (Extremely sorry if this makes little sense)
You should not use both the UITableViewController and the UIViewController. UITableViewController is a subclass of UITableViewController so all you need the UITableViewController and you should drag the outlet to it.

iOS - Having 2 table views and other elements under one TableViewController

I'm trying to make an interface like this one:
But I get the following error in XCode: Illegal Configuration: Static table views are only valid when embedded in UITableViewController instances
That controller is a subclass of UITableViewController, so I don't really understand what the problem is, any insight?
First of all, I think you're saying that ProfileViewController is a subclass of UITableViewController. If that is the case, the top level view should be a UITableView not just a UIView. And the error does make sense. If you want to create a static table view, it needs to be embedded in it's own UITableViewController, which is what you get when you drag a UITableViewController from the Palette to the storyboard.
Amended to answer question in comments
So starting from scratch. Drag a TableViewController onto your storyboard and change the class to ProfileViewController. That gives you your tableview with the prototype cells. Then drag an empty view to near the top of the TableView. This will add a headerview to the tableView. (Every tableview has a subview for a header and a footer. This is different than the section headers). Now make that header view taller and drag your other elements into it: the segmentedButton, the search field. Drag your UIImage View. then drag another tableview and position it next to the image view.
Now create a subclass of NSObject NOT NSTableViewController like so.
#interface MiniTableViewController : NSObject <UITableViewDelegate, UITableViewDataSource>
And put the datasource and delegate methods for that minitableview in there. Back on the story board, drag an object to the hierarchy change the class to your MiniTableViewController, and connect the delegate and datasource outlets from your minitableview to the MiniTableViewController in the hierarchy. Make sure you're using the assistant view. Then ctrl-drag from the MiniTableViewController object to the ProfileViewController.h (right before #end) and create an IBOutlet. Now you can access your new custom object from ProfileViewController. You can also create an IBOutlet in MiniTableViewController and connect it to ProfileViewController if you need MiniTableViewController to send messages to ProfileViewController.
A UITableViewController can only have one Table View. You have two. You have to find another way to do it.
Have you put a UITableView in your xib ?
If yes, have you bind this UITableView to your controller?

How to add Both table view and View in a View

I am trying to create a Navigation based application where the rootviewcontroller has a uitableview in it. I would like to change this so its just a standard uiview however everything I have tried so far keeps giving me errors.
First of all you create navigation based application and then delete TableView from rootViewController.xib and take it view from library and connect it and more thing is that to insert uiviewcontroller instead of uitableview in rootviewcontoller.h file and build & run your project its work fine.
How can I add both table view and a uiview to that view?
Follow this steps:
1) Go to the .XIB and remove the UITableView from the root.
2) Add an UIView and put an UITableView inside of it.
3) Change the type of controller from UITableViewController to UIViewController ( you can change this on the 3rd tab):
4) Go to your class and change his parent from UITableViewController to UIViewController.
5) Add the UITableViewDataSource and the UITableViewDelegate protocols.
6) Connect your UITableView data source and delegate to your class from the .XIB

Resources