Adding Outlets to View Controller via Table View Controller - ios

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.

Related

How to create a separate view in Storyboard to be included programmatically in UITableView?

I have a UIViewController with a UITableView that is fed with data from the local database. When the user first launches the app (after installing) the table view is empty and I display a UIView in the middle of the table view that contains a UIImage, a UILabel and a UIButton (a call to action).
The first version of this view I built programmatically, which was no good to me because every time I tweaked something I had to build the app again. Then I switched to the storyboard but had to drag a UIView to the middle of my tableView. It is working now but I don't like the way it is, I can't edit my table view cells without having to move the UIView out of the table view.
I'd like to have a way to build this view entirely separated from my tableView (or even from my view controller in question) and then reference it in the viewDidLoad call of my view controller.
Unfortunately Xcode does not allow us to drag views directly to the storyboard so I'm pretty lost here.
Please tell me if I haven't been clear enough. I appreciate any help you could give me.
UPDATE: It'd be particularly awesome to me if I could also create a custom Swift class for this view of mine and reference it in the storyboard. And then in my viewDidLoad I could simply instantiate my custom view.
Thanks in advance.
Create a XIB file in which you can drag a view (without a view controller).
In your code you can load the XIB using NSBundle.mainBundle().loadNibNamed("MyXibName", owner:self, options:nil).
In the XIB file you can give the UIView a custom class (like you can do with view controllers in storyboard).
You then of course have to retrieve the view from the array returned by loadNibNamed and cast it to your custom class.

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.

how to place a UIViewController in another UIViewController through nib in xcode

I have developed a DetailViewController, derived from UIViewController. Now I want to use this DetailViewController inside another InfoViewController's layout. I found one way to do this by using addSubView method. But what I am looking for is to plot it through nib file, like other UIViews. I want to plot DetailViewContoller inside InfoViewController's layout through nib file. Is this possible?
Any response will be thankful.
Yes it is possible..
First remove the referencing outlet for view in DetailViewController.xib.
And in InfoViewController.xib drag-drop Object and edit the custom class to DetailViewController.
Now drag-drop view in InfoViewController.xib and add what ever subviews you want to it. Now add new view referencing outlet to DetailViewController which is under objects.
Hope this will help you.

Refactoring a UITableViewController subclass to a UIViewController subclass

In my app, I wanted to show a table in the "full screen," so I created a subclass of UITableViewController. When I want to show the table, I just instantiate it and use pushViewController:animated:. Now I've decided that I actually want to show it as a modal, so I want to give it a navigation bar with a "Done" button. I believe this means that I now need to make this a UIViewController subclass instead of a UITableViewController subclass, since it will now be more than just a table. I'm not really sure if this is something that can be done, though; I've created an xib, but Xcode doesn't seem to want to let me use that xib to create IBOutlets in the .h file, so I don't think the two are "connected."
I ran into this problem once before and worked around it by just creating a new UIViewController subclass and xib and just copy-and-pasting all the stuff I needed from the UITableViewController subclass's files into the new subclass's files. I knew then as I know now that that was a hacky and unpleasant solution, though. Does anyone know how something like this can be done properly?
Also, to avoid this problem in the future, should I just never make top-level views like this in the future and just make sure everything I use pushViewController:animated: or presentModalViewController:animated: with is a UIViewController subclass? Or is it safe to do what I've been doing?
Several things you mention in your question indicate some misunderstandings. First, if you're pushing you table view controller, then it has to be embedded in a navigation controller, and thus will have a navigation bar -- you can add a done button to this bar, if that's all you're trying to change. No need to refactor your code.
If you want to use a UIViewController instead of a table view controller, you should be able to hook up your nib. Did you change the class of the files owner in the nib to your UIViewController class? After you do that, you should be able to hook up the outlets.
There's nothing "hacky" about copying and pasting code from a table view controller into a view controller. I do this all the time, rather than writing out all those files.
I'm not sure what you're asking in the last question. How you get your table view on the screen (pushing or presenting) has nothing to do with whether what you're showing is a table view controller or a view controller. You should use the one that best fits your needs.

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