I am using a split view controller and wanting to add multiple table views to the master view controller.
So I can take advantage of prototype cells that (I believe) you can only get from UITableViewController I have put the UITableViewController into a second storyboard for the app. I am then substantiating it with:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"SecondStoryboard" bundle:nil];
MyTableViewController *myTableViewController = [storyboard instantiateInitialViewController];
I then add the view of this UITableViewController as a subview of my UIViewController.
[self.view addSubview:myTableViewController.view];
When I run this, I can select and highlight rows just fine. But didSelectRowAtIndexPath is not being called for some reason?
Thanks for any help,
Richard
Add this line
myTableViewController.view.delegate = myTableViewController;
or Make sure you have done the same in XIB(Interface Builder).
Turns out that I needed to add the uitableviewcontroller as a child controller of the uiviewcontroller as well. Just adding the view alone was not enough.
Related
I am creating a reusable view for which I have created a separate Storyboard. This reusable view will be added in different UIViewController is Main.StoryBoard. For this I followed storyboard reference. But I am not sure how to add Storyboard as a subview inside a UIViewController having some definite frame.
Please let me know if you want to have a screenshot as to how I am designing the screen.
first you need to get the reference of the storyboard from the different storyboard.
UIViewController *viewControllerToAdd =
[[UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil]instantiateViewControllerWithIdentifier:#"viewForPopover"];
//Instead of MainStoryboard you write the name of the Storyboard which you have created separately
the you write these lines
[self addChildViewController:viewControllerToAdd];
[self.view addSubview:viewControllerToAdd.view];
[viewControllerToAdd didMoveToParentViewController:self];
This much should probably do, i havent tried it yet
make reusable UIViewController and then addChildViewController wherever you want. Below i made RemarksViewController which i used in many views of UIViewController
RemarksViewController *vC=[[UIStoryboard storyboardWithName:#"yourStoryboardName" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:#"showRemarks"];
[self addChildViewController:vC];
vC.view.bounds=self.view.bounds;
[self.view addSubview:vC.view];
[vC didMoveToParentViewController:self];
i have UITableViewCell with tableView and i need show new controller if user select in my cell. But, navigationController and UIStoryboard doesn't work! How i can do this?
I think what you want to ask is after u tap a UITableViewCell , a new UIViewController would be pushed in. For that, you need to first embed in a navigationController to create a stack of the pushed view controllers. Then, inside tableView:didSelectRowAtIndexPath: add this :
YourController *yourController = [self.storyboard instantiateViewControllerWithIdentifier:NSStringFromClass([YourControllerStoryboardId class])];
[self.navigationController pushViewController:yourController animated:YES];
Check if you have set the delegate of your UITableView. Clean and Run your code.
I have a storyboard that handles all of my applications UI, apart from the header on each page which is handled by its own .xib file following this guide:
http://patientprogrammer.wordpress.com/2012/03/12/re-usable-subviews-in-ios/
Within my header .xib I have a button that I want to have when clicked load a view that is part of my story board.
I have tried:
- (IBAction)clicked:(id)sender {
UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
someViewController *storyViewController = [mainStoryBoard instantiateViewControllerWithIdentifier:#"someViewController"];
[self.navigationController pushViewController:storyViewController animated:YES];
}
However as my class uses the interface UIView controller navigationController is not found, what can I do to launch a view within the story board from my UIView.
Or if there another interface I can use that will still let me have this as a subview.
what can I do to launch a view within the story board from my UIView
This is bad. A view is a view. Its purpose is to show something to the user, not controlling the app.
UIViewController is where you will need to do this. The navigationController is a property on this class, not on UIView. Read UIViewController class reference for more info.
I have a custom UIView which is a xib file and then a class that controls this view. I also have a storyboard which a lot of different view controllers inside. How do I perform a segue from the UIView to a specific UIViewController that is inside the storyboard?
Thanks
You can't do that. What you can do is give the UIViewController a storyboard ID, using the menu on the right of the interface builder.
Then call it programatically, like so:
MyCustomViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"MyViewController"];
[self.navigationController pushViewController:vc animated:YES];
You could put a ViewController into the Storyboard, set the class to your custom ViewController. Then, if you have class files for the view in the xib, set your custom view as the VC's view (already saves some code in loadView) and then just add a segue from the custom VC to the other view controller. To trigger that segue, you have to call [self performSegueWithIdentifier:#"identifierOfSegue"] in your custom ViewController.
My aim is to make a UITableView with a certain level of navigation. All I will be using are table views so I really want to go with UITableViewController and UINavigationController.
I created a subclass of UITableViewController, here is the xib file:
It's automatically generated as the class is UITableViewController subclass. Is it enough to get a navigation bar, or should I add something on the xib.
And the relevant code in the .m file is the following:
- (void)viewDidLoad
{
[super viewDidLoad];
UITableViewController *tableViewController=[[UITableViewController alloc]initWithNibName:#"ViewController" bundle:nil];
UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:tableViewController];
self.view.window.rootViewController=navController;
//Create the modal for the UITableView
array1=[NSArray arrayWithObjects:#"Categorie 1",#"Categorie 2",#"Categorie 3",#"Categorie 4",#"Categorie 5",#"Categorie 6",#"Categorie 7",#"Categorie 8",#"Categorie 9",#"Categorie 10", nil];
}
And here is what I got:
I was waiting to see a navigation bar at the top of the view. I know I am missing something, so please bear with me and give help. Thanx.
In your MainWindow.xib, you have to drag a UINavigationController, then a UITableViewController. Set the class of the UITableViewController to your table view controller subclass. Also make sure that the table view controller is set as the root of the navigation controller.