iOS: UIViewController is Not Being Pushed Problem - ios

I'm working on a new app where there is a "main" UIViewController with some UIButtons and once the user clicks on the buttons, the application is navigating to another UIViewController.
For some reason, the UIViewControllers are not opened, when you click on the button nothing happens. Several points that anyone who tries to help should be aware of
I'm using code and interface that are very similar to another app that I had created and is working fine (I triple checked the code, and it's the same in the area that makes the UIViewControllers navigation)
I triple checked the Interface Builder items and their connection to the IBOutlet us fine (view is connected to view, File's Owner is set correctly, etc...)
I inserted NSLogs to the UIViewController that is not being pushed and I can see that initWithNibName is being called, but viewDidLoad is not being called.
I'm using basic-simple code to create and push the UIViewController: alloc+initWithNibName and then presentModalViewController or pushViewController (none of them work) and as I said, in another app with the same mechanism it works fine.
I don't know where to look! Maybe I unchecked by mistake some "Enable" button in Interface Builder or something like that.
Did anyone encounter something like that or may have some new thought regarding to where I should be looking?

Hmm, strange. Things i can come up with now are: dit you call [super ] in your viewDidLoad?
Is it stacked behind another view? Run instruments to see if all the things on the pushed view are allocated, so you know if the whole view is loaded. And you use a navigation controller? than you use pushViewController. When you are not and want a model you use presentmodalviewcontroller.

Related

Not able to make ctrl-drag reference/delegate from uittabcontroller to app delegate

This has really been pissing me off for a while now, and I have no idea how to get further. I have created a tabbed application hence getting the default UITabBarController + 2 View controllers that are nested within this. Fair enough. Now I noticed the viewcontrollers viewDidLoad methods wasn't called when switching around. Ok, so I find theres a tabbar delegate for when a viewcontroller gets "tabbed." Now my problem is the delegate method which I've placed in AppDelegate, is not being called. I have tried in all ways I know of to make a reference to the given tabbarcontroller (to se the delegate programmatically) and I have tried ctrl-dragging the delegate to anywhere possible. Am I doing sth wrong? (because everywhere I look this seems to not be a problem, and people are holding reference to their tabbars).
Thanks
I used this code to get a reference to the tabbar, so I could set the delegate programmatically:
UITabBarController *tabBar = ((UITabBarController*)self.window.rootViewController).delegate = self;
Very simple, I guess I was running late night hours yesterday.
Yet the issue was clearly using storyboard and then trying to make an outlet in app delegate (I still dont think that is possible).
You have to set your view controller's class in storyboard if you want to be able to make references. Select your view controller in storyboard. On the right panel go to Identity inspector and in the Class field set the name of the class. The you should be able to make references and also viewDidLoad should be called.

Adding a subview that stays in place as you navigate through views

I am looking to create a subview that looks like a banner drop down view from the Navigation Bar.
or like this
I feel like I see this effect all the time but have been struggling for a while to recreate this. I have it working on single view applications but I would like it to stay in place as I navigate from view to view. Right now I have the view setup in the storyboard and would like use this because I had issues attempting this programatically.
To create this "drop down banner view" and have it stay in place (until the user dismisses it) as a user navigates from screen to screen I see two solutions, each of which I have stumped myself on.
Create my own master view as the window.rootViewController
I see this as the cleaner solution in the end, but a bit harder to implement. Would it be possible to create a blank UIView as the rootViewController and whenever the app needs to drop down an alertBanner it could tell the rootController to do so? The view hierarchy would be something like
window -> masterViewController -> alertBannerController -> Navigation Controller -> otherViewControllers
but I cannot seem to have this set up the proper way.
Create an instance of my AlertBannerView from a subclass of the UINavigationController
Instead of calling the method to create a dropDownBanner from the rootViewController another option I see is subclassing the navigationController to be able to drop down this subview. This way it could still persist as the user navigates around views.
Once again I am having problems setting this up properly to work with the existing NavigationControllers
Conclusion
I do not know what is the best approach here.
This is different than the Apple Push Notifications drop down screen because I would like to customize it for the apps UI
Any tips on how to properly set up a custom view as the rootViewController would be great (where do I do this? what methods do I need to call?)
The problem to solve here is to have the alert banner view remain in the window until the user dismisses it even if they are navigating from screen to screen.
Thanks!
Depending on which version of iOS you're working with, yeah there are a lot of possibilities and ways of doing this. In fact, there are a lot of people who already have.
Best place for getting some ideas on how to attack this problem, to me, is by looking at an existing solution. CocoaControls is a great place for this.
For instance, here is a relatively recent one: https://www.cocoacontrols.com/controls/mpgnotification
And here is a list of a bunch of them ( they aren't sorted in any particular order unfortunately though ) : https://www.cocoacontrols.com/search?utf8=%E2%9C%93&q=notification

What type of ViewController should I use in this simple iPhone app

I'm trying to make my first Xamarin iPhone app. I have 2 views right now and i'm not sure how to be wire it up and then switch to the 2nd one.
AuthenticationViewController. This is a simple login/create account view.
TabbedViewController. A few sub views all connected by a tab controller. eg. listview, settings and about/info.
right now, i'm setting the root = new AuthenticationViewController and that works fine. just not sure how to swap roots and if this is the correct way to do things.
or should this all be done with a storyboard (which i think is an overkill, here)?
The user should always understand where he is. For that Apple suggests animations removing old content and showing new content. One possibility is the UINavigationController. You can create an empty UINavigationController with your AuthenticationViewController as Root. When the authentication succeeded, you can push your new ViewController (which is the TabbedViewController) on the stack. If you have a log-off in your TabbedViewController, you come back by PopViewController.
The other alternative is the PresentModalViewController. In the appearing controller you define the modal transitions style. This can be anything and especially for this a FlipView-Animation is in my opinion not a bad choice.
All this exists in Xamarin like in iOS.
StoryBoard is doing the same thing but visualizes what should happen underneath. (like InterfaceBuilder for the ViewController itself).
At least in objective-c you can change the root view controller of the window without problems. The only drawback is that you cannot apply transitions doing things this way. But it is totally fine to do so.

ios methods becoming zombies

I added uiviewcontroller subclass in my arc enabled project, i added a button created the ibaction for it and inside it contains no code, all done through interface builder no manual code, but when i am tapping the button i am getting exc_bad_acess. Instrumentation saying its a zombie attack when pressing button. I really dont understand whats going wrong. I created the new project and done the same thing it is working perfectly. Same thing happening when i am defining method to dismiss keyboard (resign first responder).
this generated when i crtl+dragged from button to interface implementation, i choose the ibaction and name and this code is generated.
- (IBAction)pushh:(id)sender;
and the implementation inside .m file
- (IBAction)pushh:(id)sender {
}
thats all ...
Just to wrap up the offline conversation, a couple of thoughts:
Your zombie is undoubtedly a result of the ecnObj falling out of scope. If it's an ivar of the view controller, then that premature release problem goes away.
You do not want to create a new view controller and then use its view in transitionFromView. If you want to transition between view controllers (in iOS5) you should use pushViewController or presentViewController (or if you're using a container view controller, you can pursue transitionFromViewController). See View Controller Programming Guide's discussion of "Presenting View Controllers from Other View Controllers".
My solution was to delete the button iboutlet in ib, also delete the ibaction in ib, and then connect it back.

Segues from a subView

Just trying to teach myself storyboarding and have run into a question I was hoping people may have an answer to.
I wanted to create a reusable upper toolbar so that in case I ever had to change it, it would update all of my scenes. I created a sized ViewController in my storyboard. I then load it into a subview of each of my scenes using the menu's identifier. THat seems to work pretty well (although, feel free to tell me that's the wrong way to do it).
Here's where the problem starts. On that top toolbar, I have a UIButton which I connect to another sized ViewController in my storyboard as a popover. Basically, a drop down menu. If I just load up the top toolbar, works fine. If I connect just a regular button to that popover scene using a segue, that works too. If, however, I try to click the button and follow the segue while the toolbar is within a subView I crash with EXC_BAD_ACCESS. I presume I'm not allowed to spawn a popOver from a subView or follow a segue within a subview? The latter seems wrong since you effectively do that with any UI object.
How else should I handle this?
Thanks!
I'd recommend using a UINavigationController and setting the toolbar to include your UIButton (as a UIBarButtonItem). If you have any trouble "keeping track" of the toolbar or button you can subclass UINavigationController, add the UIButton (or entire toolbar) as a property of the subclass, and access it from any subsequent view through the self.navigationController property (might violate strict OO, but you could use a protocol).
As for the popover, I think you're OK on iPad but not on iPhone. There are custom projects on github to implement UIPopoverController, and indeed the Facebook app makes use of a custom popover for notifications in their app. iPhone raises an exception if you try to show a UIPopoverController.

Resources