Objective C: NavigationBar for PageViewController - objective-c

I have a UITableViewController was added to a UIPageViewController as the pages, the program push PageViewController and show UINavigationBar on the top of the PageViewController, I want to add UIBarButton to UINavigationBar to control UITableViewCells, but can only do it on the screen of PageViewController, that means, all events related to this button must be handle in PageViewController, because all these events are related to TableView cell controls, I want them are handled in UITableViewController.
I tried many ways, like define a IBOutlet in UITableViewController, and when viewDidLoad, set self.NavigationItem rightitem to this IBOutlet item, all did not work.

I don't know how you're creating the UINavigationController but I assume you're doing it from PageViewController. If that's the case, then make sure that the PageViewController pushes onto the UINavigationController the UITableViewController. You cannot add the UITableViewController to the PageViewController.
In other words, the PageViewController creates a page with a UINavigationController. Then you push onto UINavigationController the UITableViewController.
At that point when inside your subclassed UITableViewController, you should have access to self.navigationItem, etc...

Related

How to hide UITabBar when a collapsed UISplitViewController shows a Detail ViewController?

I have a window with a UITabBarController as rootViewController. The UITabBarController has two children: A UINavigationController and a UISplitViewController (according to the latest docs this should be OK, and it works except for the following problem).
Both the UINavigationController as well as the UISplitViewController show a MyMasterTableViewController which can push instances of MyDetailViewController.
MyDetailViewController has self.hidesBottomBarWhenPushed = YES to make the TabBar disappear on push.
When I push MyDetailViewController onto the UINavigationController the UITabBar disappears as expected. When I show MyDetailViewController on the UISplitViewController while it is collapsed, I would expect the same, since the collapsed UISplitViewController contains only a UINavigationController with the Master which pushes the Detail ViewController. It doesn't however.
How can I let a collapsed UISplitViewController make the UITabBar hide on showing MyDetailViewController like the UINavigationController does?
Unfortunately you cannot take advantage of Hide Bottom Bar on Push while using a UISplitViewController inside a UITabBarController. You can override the UITabBarController viewControllers and for the iPhone only, point to the MasterViewController's UINavigationController in the Storyboard. This is where you can Hide Bottom Bar on Push. The UISplitViewController for some reason does not respect the flag on a push, probably for iPad purposes.enter image description here

swipe to change uiviewcontroller

I have a viewController which contains data which will remain static on the top half of the viewController. The bottom half contains 4 buttons and 4 UIViewControllers linked to the 4 buttons which are loaded earlier. And on respective button click the respective UIViewController will be show and rest of them will be hidden. I am just making viewController visible and invisible on the button click.
I want to make them change on swipe. so the UIViewController will change with the swipe and the button state for the respective UIViewController will also change with swipe.
I am not using storyboard and using xcode5.
One simple way - you can use UITabBarController to handle all this array of view controllers:https://developer.apple.com/library/ios/documentation/uikit/reference/UITabBarController_Class/Reference/Reference.html
And to change them with swipe - just add a UISwipeGestureRecognizer: https://developer.apple.com/library/ios/documentation/uikit/reference/UISwipeGestureRecognizer_Class/Reference/Reference.html like this:
UISwipeGestureRecognizer *swipeRecognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:#selector(changeTabs:)];
[self.view addGestureRecognizer:swipeRecognizer];
[swipeRecognizer release];
And in changeTabs: do this
[self.tabBarController setSelectedViewController:nextViewController];
Another more solid way is to use UIPageViewController : https://developer.apple.com/library/ios/documentation/uikit/reference/UIPageViewControllerClassReferenceClassRef/UIPageViewControllerClassReference.html
You wrote: "so the uiviewcontroller will change with the swipe and the button state for the respective uiviewcontroller will also change with swipe." - this is silly. Just use either tabs as I suggested and remove those buttons or use UIPageViewController which already has page indicators and will handle their logic itself

How to customize UINavigationBar with XIB?

UIViewController has a property called UINavigationItem.
So how can a UIViewController refer to UINavigationBar?
The UINavigationBar is not displayed yet till UIViewController is pushed into a UINavigationController. So it's not available in viewDidLoad.
So how do we customize it?
I added UINavigationBar to the XIB. However, how do I specify that I want to use THAT UINavigationBar rather than the one provided by UINavigationController?
I added UINavigationBar to the XIB. However, how do I specify that I
want to use THAT UINavigationBar rather than the one provided by
UINavigationController?
You don't. The navigation bar is the nav controller's responsibility -- your view controller doesn't get to swap in its own nav bar. Each view controller has a navigation item that it can set to customize simple things like title and buttons, and you can get the navigation controller's nav bar when the view controller is pushed onto the navigation stack using the controller's navigationController property.

Add UITableViewController to other View

Is it possible to embed (add as subview) a UITableViewController into another View Controller programmatically? I found a few answers here on StackOverflow but none worked for me with ARC and iOS6 SDK.
I know you can do this easily with Navigation and TabBar controllers but I am more curious about adding tableviews to a regular View controller. I need my tableview to occupy the lower part of the available screen space (I need the rest for other purposes, for which neither tab nor navigation types are suitable).
When I tried to do it, however, it did not work. I instantiated a subclassed UITableViewController, but when I added it to my self.view as a subview, the compiler said I tried to use "incompatible pointer types." Not only that, my instantiated UITableViewController does not have a .frame property, so I cannot set it dimensions, which would be the whole point of this exercise.
Building upon ogres answer, you should add the tableViewController's view as a subview, but it is not everything. The tableViewController is a viewController and it needs to know its parent and its children, to do its viewController-job correctly. I do not know any details here, but there is an entire talk about this from WWDC 2011 called "Implementing UIViewController Containment".
One problem I have experienced when only adding the view as a subview is that target actions don't seem to work. Tapping a UIButton or similar causes either a EXC_BAD_ACCESS or a unrecognized selector sent to instance.
So I recommend that you do something like this:
UIViewController *vc = //Your tableViewController
[self addChildViewController:vc]; //Important
[self.view addSubview:vc.view];
//If you want to set the frame, set the frame of the tableViewController's view
vc.view.frame = ...
yes , you can use tableview in another view without any problems
UITableViewController, but when I added it to my self.view as a subview
are you trying to add viewcontroller as subview or its view ? ( viewcontroller.view )
UITableViewController does not have a .frame property,
of course it does not have .frame property , it is a view CONTROLLER , you should see .view.frame

How to TabBarController display differents Items?

On my firstViewController I have a tabbar that contains my firstViewController and a helpViewController.
When I click on a button from the FirstViewController, I push a NewViewController. But, when this view is pushed, I want to change the content from the TabBarController to display other ViewControllers, like infoViewController, optionViewController and NewViewController. Is that possible?
The First Image represents my application. The FirstViewController has a button that will push the NewViewController. When the user clicks this button, I want that my app shows what is in the second image. Is possible?
Yes, this is possible (I just did a proof of concept in Xcode). Assuming that you are using storyboarding, you need to make your initial view controller a UINavigationController otherwise you won't be able to use the push segues. Then, make the first UITabBarViewController the root view controller of the navigation controller. Put an entirely new UITabBarController into the storyboard, and then put a UIButton into the firstViewController and link it via a push segue to the new (second) UITabBarController.
When you tap the button the old tab bar will slide off, and the new one will slide on.
Here's an example of how it all looks:
!!This app uses navigationController and TabBarController!!
Using the storyboard I saw each piece of the app, then I had the Idea: Insted of pushing the NewViewController, how about push a tabBarController? When the user clicks the button, the app will push the tabBarController with 2 TabController`s.
Just add New File to your project, sub classed UITabBarController. Then add this code to the init method of your tabBarController: self.hidesBottonBarWhenPushed = YES;
On ViewDidLoad just alloc and init what views you want to display on the tabBar and
self setViewControllers:[NSArray arrayWithObjects: vc1, vc2, vc3, nil]];
Working fine here :D
You can nest TabBarControllers. But that would look strange. And the first TabBar wouldn't be changed. Pushing a TabBarController into a TabBarController is not possible because TabBarController does not support pushViewController. Thats only possible with a NavigationController.
Anyhow you can change the content of the TabBar completely programatically.