Could not set the title of tableview - xcode

I embedded tableviewcontroller into a navigation controller, set the title, but it does not show when I run the app.
What is wrong?
This is the setting of the tableviewcontroller
Here is the setting of the navigation controller

First check, your NavVC must be initial VC.
If not then try this piece of code
-(void) viewWillAppear:(BOOL)animated {
[[self navigationController] setNavigationBarHidden:NO animated:YES];
}

you must be presenting the plain table view instead of navigation controller. What you need to do is make you tableview as root view for a navigation controller and present the navigation controller.
var nav: UINavigationController = UINavigationController(rootViewController: vc)
//then present the nav

Change the initial VC from Navigation Controller to your TableViewController

I did not set the StoryboardId for Navigation controller.

Related

How to restrict UISearchController from hiding view Navigation Bar in IOS8

I have a UIViewController embedded in a popover. This controller has two subviews, a UINavigationBar and a MapView. I try to implement the new search Controller i.e. UISearchController as UISearchDisplayController is deprecated in iOS8.
When I click in the search bar (displaying two scopes), everything is all right, and the navigation bar is still visible. But when I start typing in the search bar, the navigation bar and the keyboard disappear, replaced by a dim map view. I tried to add self.searchController.hidesNavigationBarDuringPresentation = NO; in the updateSearchResultsForSearchController: method as well as searchBarShoulBeginEditing: method, but got no result. (note that the controller viewDidLoad defines self.definesPresentationContext = YES;)
Any idea to force navigation being displayed anytime?
First set this property self.definesPresentationContext = YES; in ViewDidLoad. Then implement searchBarTextShouldBeginEditing and searchBarTextDidBeginEditing methods as such:
-(void)searchBarTextShouldBeginEditing:(UISearchBar *)searchBar {
[searchControllerMain setActive:YES];
[searchControllerMain.searchBar becomeFirstResponder];}
-(void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
[searchControllerMain setActive:YES];
[searchControllerMain.searchBar becomeFirstResponder];
searchControllerMain.hidesNavigationBarDuringPresentation = NO;
}
It will work!!

SWRevealViewController push Segue

I am trying to use a SWrevealViewController for sidemenu . One of the options on it is "User Profile" . Since I access user's profile from various other views , I would like to have to have a push segue to this VC. However , a push segue is not working from SWRevealViewController to UserProfileVC.
Can anyone suggest how I may use a push sugue from SWRevealVC?
Here's my solution:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle: nil]
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"YOUR_VC_STORYBOARD_ID"];
SWRevealViewControllerSeguePushController *segue = [[SWRevealViewControllerSeguePushController alloc] initWithIdentifier:#"ANY_ID" source:self destination:vc];
[segue perform];
Swift version will be
let vc = self.storyboard?.instantiateViewControllerWithIdentifier("LoginRoot") as! UINavigationController
let segue = SWRevealViewControllerSeguePushController.init(identifier: SWSegueRearIdentifier, source: self, destination: vc)
segue.perform()
Navigation controller is UIViewcontroller. i used navigation controller otherwise use UIViewController object.
Create a custom segue from your Reveal View Controller to your side menu view controller using the storyboard editor. Set the identifier as "sw_rear", kind as "Custom" and class as "SWRevealViewControllerSegueSetController".
With this, if you create ordinary "push" segues from your menu view controller to other view controllers they should be pushed normally.

XCODE : Changing which view controller BACK button segues to

Is there a way to change the "parent" of a view controller so you can specify which view controller the back button will segue to without creating a custom back button?
Or is the only way to create a custom back button with a custom action?
If you have access to the navigation controller, you could manually insert a view controller in to its stack of view controllers [self.navigationController setViewControllers:] before the current view controller. That would allow the navigation controller to perform its regular actions yet still navigate back to your desired view controller.
Try To create a custom button like
UIBarButtonItem * buttonBack = [[UIBarButtonItem alloc] initWithImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"Back" ofType:#"png"]] style:UIBarButtonItemStylePlain target:self action:#selector(onBackClick:)];
[self.navigationItem setLeftBarButtonItems:#[buttonBack] animated:YES];
and make a method..
- (IBAction)onBackClick:(id)sender
{
// your code
// Write your code what you want to do...
}

How to use custom Navigationcontroller in AppDelegate by using a Storyboard

I've got a problem concerning Navigationcontroller in AppDelegate. I'm using a storyboard, which looks like this:
As a result of using Push notifications, i've got the following function in my AppDelegate File:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
//...
}
When the notification arrives I want to initialize the "Detail View" - Controller which needs an ID as a parameter. This ID is part of my payload so it is present in didReceiveRemoteNotification.
I'd like to to the follwing:
DetailView *detail = [storyboard instantiateViewControllerWithIdentifier:#"detail"];
detail.conversationID = theID;
[self.navigationController pushViewController:detail animated:YES];
My question at this point is: how can I get the navigation controller? I've searched for a function like "getNavigationControllerByIdentifier" or something like this, but found nothing. I can't instantiate the Detail View Controller directly because the navigationbar is missing there.
I hope you understand what I mean - if you think my approach is completly wrong please correct me ;o)
Just another small information: It's not important for me that the back button in the Detail View Controller goes back to the Table View - it's enough when it links to the controller with the button "Load Table View".
Thank you for help!
UINavigationController is a UIViewController subclass and can also be assigned an identifier in the storyboard.
Use -instantiateViewControllerWithIdentifier: to create the UINavigationController and it's root view controller. You may need to instantiate all of the intermediate controllers in code and modify the navigation controller's viewControllers property to set up the appropriate navigation stack. This way when the app launches into the detail view, they can find their way back as if they had manually pushed all the way through via the interface.
You can use rootViewController on your window object.
UIViewController *rootViewController = self.window.rootViewController;
// You now have in rootViewController the view with your "Hello world" label and go button.
// Get the navigation controller of this view controller with:
UINavigationController *navigationController = rootViewController.navigationController;
// You can now use it to push your next view controller:
DetailViewController *detail = [navigationController.storyboard instantiateViewControllerWithIdentifier:#"detail"];
detail.conversationID = theID;
[navigationController pushViewController:detailViewController animated:YES];

Setting badge value in UITabBarItem in UIViewController

I am adding UITabBarController to the window, and setting the viewControllers property of the UITabBarController to the array of ViewControllers.
If i am setting the badge value inside the viewController then its working fine.
self.tabBarItem.badgeValue = #"3";
But if i am setting the viewControllers property of the UITabBarController to the array of navigation controllers which is having view controller as the rootviewcontroller, then its not setting the badge value.
Any suggestions ??
Thanks
Yes, i got the answer.
[[self navigationController] tabBarItem].badgeValue = #"3";
Or this:
[[self.tabBarController.tabBar.items objectAtIndex:2] setBadgeValue:[NSString stringWithFormat:#"%d",[UIApplication sharedApplication].applicationIconBadgeNumber]];

Resources