How to know if my UIViewController is being showed as a UIPopoverController - uipopovercontroller

I have a UIViewController which I show sometimes as a UIViewController and some others like UIPopoverController, but I want them to show a different message depending if is showed as one or another, is there a line of code which helps me to know this?
something like:
if(self.popover) NSLog(#"this is a popover");
else NSLog(#"this is a viewcontroller");
thanks in advance

Related

Two taps required to make hidden UINavigationBar appear

I have a UITableViewController which contains cells of different languages. When the user taps a cell, they are taken to a UIPageViewController which shows the appropriate leaflet in that language. That part is working well.
I have implemented the use of the following code to make the UINavigationBar hidden and to appear on a tap:
self.navigationController.navigationBar.hidden = YES;
self.navigationController.hidesBarsOnTap = true;
I have that code in my viewDidLoad. I don't have any gesture recognisers, but both on the Simulator and on the device, to get the UINavigationBar to appear, I have to tap the screen twice. Why do I have to tap twice?
If I do the same on a UITableViewController, I only have to tap once, so it seems something specific about this UIPageViewController and I can't quite figure out what.
I've looked around and I can't seem to find anyone with anything similar.
On guidance on this would be appreciated.
Try this :
[self.navigationController setNavigationBarHidden:YES animated:YES];
If that does not work, can you post the code for your methods relevent to this issue?
Could probably help more with more info.

Loading controller on top of view from storyboard (or nib if necessary)

I've seen lots of topics about this but i could not get this to work as i wanted, i'm sorry that this will look like a duplicate.
What i'm tyring to do :
Show a view from a storyboard VC (or a .xib, it's really up to what's "best") as if it was an alert. The user has to interact with it and then dismiss it.
Here is what i have :
A viewcontroller in my storyboard ; its linked to the corresponding .h and .m files and everything works fine on that side.
Note : That viewcontroller is "alone", there is no segue leading to it.
Now i'm in my active VC from my app flow, and i'm doing this :
ADFViewController *adf = [[ADFViewController alloc]initWithNibName:#"ADFView" bundle:[NSBundle mainBundle]];
adf.xxx = yyy // just setting some data that the user interacts with.
[self.view addSubview:adf.view];
(The VC has a button that does [self.view removeFromSuperview]; to dismiss itself when the user decides to do so.)
I've also tried using this :
adf = [self.storyboard instantiateViewControllerWithIdentifier:#"ADFViewController"];
Both don't work or "almost" work.
They're linked like they should, the storyboard and Nib name corresponds (i've tried both).
As a result I just get a blank screen. The view size is 300x300 so It should at least appear somewhat on my screen. But all i get is a blank screen (the view background).
When that is working, I intend to make the background transparent so it really looks like an alert but i'm not even up to that point. And maybe i'm struggling even though i'm going in the wrong direction.
Questions :
Am i doing something wrong?
Is this the right way of achieving this?
What should I do?
Thanks a lot for your time.
Getting a view to look and behave like an alert (with the transparent background, etc.) takes some work because you can't subclass UIAlertView. I would recommend using an already-built customizable UIAlertView-looking dialogue. There are a couple listed on this question:
UIAlertView addSubview in iOS7
These basically just take a view as input, so you can just pass in your view controller's view and everything else will be taken care of for you.

Popping ViewControllers when using delegation

I'm a bit weak in my Objective C I'll admit, my ultimate goal is pass data from ViewController3 back to ViewController1. Actually, that part is already done and successful. However when calling [self.navigationController popToRootViewControllerAnimated:YES] I get EXC_BAD_ACCESS.
ViewController1 <ViewController2Delegate>
- (void) didAddEventLocation:(Event *)event {
NSLog(#"Event name = %#", event.name); //Shows name successfully
}
ViewController2 <ViewController3Delegate>
- (void) didAddEvent:(Event *)event {
[self.delegate didAddEventLocation:event];
}
ViewController3
[self.delegate didAddEvent:event];
[self.navigationController popToRootViewControllerAnimated:YES];
Sorry for the poorly formatted code, just trying to simplify. Doing [self.navigationController popViewControllerAnimated:YES] has no problem, however it only takes me to ViewController2. I know I'm doing something very wrong here, but can't quite place my finger on how to resolve it. Let me know if I need to clarify.
Use Zombies to hunt down what is giving you the EXC_BAD_ACCESS. Some object has been released and is now being called on when you are popping back to the root view controller.
Try this link:
How do I set up NSZombieEnabled in Xcode 4?
Looks like, that one of your you controllers(first in my opinion) is deallocated. In VC3 method check that self.navigationController exists. Then you have to check all his VCs. I think that nothing holding first VC. Problem may be solved by using(for example) addChildViewController method of your navigation controller, or if smth will have a reference to your controllers.
Also, you can use NSNotificationCenter to send some information from one instance to another if you have problems with path between them.
HTH!

Two tab bar items should show the same UIViewContoller

What I want is to have two UITabBarItems in my UITabBar (thats not really the problem...).
So normally the first item has his own an UIViewcontroller and the second item has his own UIViewcontroller.
But I want that each TabBarItem shows the same UIViewcontroller instance.
(the functionality is nearly the same, only one label is different between those two viewcontrollers)
So I think I have to push the last viewController on top of the tabBarItemStack right after the user pushed the second tabBarItem, right ?
At the moment I'm using a StoaryBoard with two UIViewcontroller, so I really don't know how I can access the TabBarItemStack and where do I get the notification that the next tab is pushed by the user ?
Or can I alter the stack after loading the first view and push the current view on the second index of the stack ?
Hope I was able to explain my problem so anybody would understand ;-)
Thanks and Regards,
I wouldn't use the UITabBar at all in this case. I would make some GUI-object in my viewcontroller that looks like two tabs, but is acually just 2 buttons.
When you click them you switch their look so that it looks like you have switched tabs, by changing the images of the buttons. But you are always staying in the same viewcontroller all the time. And you just change the content in it.
Then you can keep track class which "tab" the user has selected by using member variables and that way you know which content to show.
The UITabBar is most useful when you have an unknown amount of tabs and you don't know exactly what they will contain. There are many times it is a lot easier to not use the UITabBar and just images/buttons with "tab-looking" layout, even when you have more than one viewcontroller.
Could you have two UIViewControllers (one for each UITabBarItem), but they are both inherited (descended) from a third (Which contains all the logic). That way you are not duplicating the code, and not faffing with the hierarchy, such that you might introduce bugs?
Load same UIViewController in both TabBar. I assume u need to hide label in first tabBar and show in second tabBar
Now in viewWillAppear Method add this code:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if(self.tabBarController.selectedIndex == 0)
{
yourLabel.hidden = YES;
}
else if(self.tabBarController.selectedIndex == 1)
{
yourLabel.hidden = NO;
}
}

searchDisplayController description is null?

The main controller is a tabBarController; one of the tabs is navigationController, then in that navigationController is a UItableView with searchDisplayController.
SearchBar is in UItableView.
However, I dont' know what I have changed (I should use snapCapture next time....). My searchBar is gone.
What I mean gone is that after my compilation, I cannot find the seaerchBar in my tab. (It is okay before I am changing sth; coz I have changed a lot, I cannot load back anymore)
I have printed a log like,
[self.searchDisplayController description]
But it is NULL.
Can sbd suggest me some directions for me to check? Thanks
In each Tab you need to add only one navigation controller, inside that you need to add either viewcontroller or tableview controller or search display viewcontroller.
You need add the objects in the above way, i dont think you have added in this format, from the image you have provided, there is only one tab in that you have added 3 navigation controllers..
I found my fault it is.
Should be
#interface ThirdViewController : ***UIViewController***
NOT
#interface ThirdViewController : ***UITableViewController***
UIViewController Class Inherits from UIResponder : NSObject
UITableViewCell Class Inherits from UIView : UIResponder : NSObject
I think that is why for tableview, I cannot show the search bar. So, in my case, I hope can help others do not make any not necessary changes, like me ##
And please do use snapCap

Resources