I have a weird problem. I have a view that's used to set user settings. I have it in a regular menu for common access and when I tap the UIButtons within this scene they execute the IBAction callback only once. Even when you spam the button. Which is a good thing.
Now, for making things faster for the user I also allow access to this same ViewController elsewhere. This time instead of using a push animation I instantiate the ViewController on my own and show it on top of everything else. For some reason in this context if I tap buttons quickly the IBAction is called multiple times.
This is a problem for me because I have a performSegue within the IBAction and it pushes the next view twice. So when the user returns it returns to the same View and if you return one more time it crashes the app.
I don't know how to solve this problem because the same UIViewController is behaving differently in two different contexts...
I'm using xcode 4.5
Related
At some point in my app, a user can move a UIView after a long press on that view. This works fine.
When the view passes over a specific region, the app has to switch to another UIViewController. The moving view is attached to this new controller. So far so good.
The problem is that now the moving view is not moving anymore (i.e. it doesn't follow the finger of the user) :-(
Seems this issue is related to the UILongPressGestureRecognizer that was fired in a ViewController that is not active anymore.
Any idea how I could handle that ?
ofcourse there might be a requirment to use a UIPanGesturerechognizer,
why dont you enable or add it to the parent view on long press?
You should implement touchesBegan, touchesEnded etc to handle moving of your view. This way, when you're switching the controller, you can still move that view.
Anyway, this idea seems to be weird at least and I'd reconsider app architecture on your place.
I have made various attempt to go storyboard only and limit my code when it comes to UI. Everytime I was getting stuck and reverting back to code. Since the release of XCode 6 and the new iPhone that have multiple screen sizes it make more sense that ever to go Storyboard only.
This time I am stuck on the following scenario. I want to create a custom search view controller that will have 2 states:
Search State. It will prompt the user for a keyword to search.
Result State. It will display the results to the user.
I am aware that this can be accomplished using the UISearchController, but the customer wants to customise the behaviour. Currently I have two view controllers and a push/show segue between them. I would like to replace that with one view controller and animate the display of the results.
Is there any way that storyboard can accomplish that. I am thinking of creating two view controllers (in storyboard) with different layouts. Both will be linked on the same class. I could create a segue between them, but then I will lose all the variable stored inside them and will not be able to animate between them.
On the transition between the two states some UI elements will be hidden and some others will be moved. I would like that to be animated.
I know how to do that in code without using storyboard, but then I will have to cover all different screen scenarios. I hope there is an alternative way.
You can do this with two view controllers, and set a segue between them. The trick is that the animation bit will have to be done in code, unless you write a custom UIStoryboardSegue to handle the animation.
I know that UIPopovercontroller does not retain itself while presenting.So we have to keep a reference to it to keep it alive
And When pressing the barbuttonitem which is presenting a popover, it does not automatically dismiss the popover, it actually will present another popover over it again and again when you press the button and do nothing special to check if there was already some popover.
I know we can have many properties to maintain every barbuttonitem's popover, but I think this is ugly...
Is there any better practice?
I'm using popovers with ARC and have not had to do anything special to maintain the reference count. As long as the popover is onscreen, there are strong references to it to keep it alive. Do you have a fail case you could post?
I consider the second issue you mention the more interesting one: pressing the barButtonItem repeatedly creates multiple instances of the popover. It's difficult to see them, because they stack up atop each other. But the shadows around the popup get darker with each added instance. The real tipoff to the problem is that every instance has to be dismissed separately.
One solution is to disable/enable the UIBarButtonItem on the way into and out of the popup. This worked well for me, but is slightly tedious. (I had to put code in two places - one in my own dismisser, and another in the popoverController's delegate's – popoverControllerDidDismissPopover: method, for the case where the user clicked outside the popover to dismiss it.)
I think that the (excellent) Stanford CS193P course addresses this issue by hiding the button while the popup is showing.
The iOS behavior actually seems like a bug. A click in the barButtonItem is outside the popover, and unless the barButtonItem's view is included in the popover's passthrough array, it is supposed to (according to the doc) dismiss the popover. But it doesn't and Apple didn't ask me.
I just checked and found that the passthrough array is initially nil, so removing the barButtonItem's view from that array is not an option. Drat.
I have created an iPad app that has 10 view controllers that swipe left and right to and from each other, and each have 2-10 pages for a vertical UIScrollView. The problem is only the first controller loads at the launch, so each swipe initially takes 10 seconds to load. After the initial swipe I can swipe back and forth with ease, but I would rather have all the load time at the beginning so the user isn't left wondering what's happening.
Is there a way to load everything at once?
Should I even be using UIViewController subclass for this?
Thanks!
You can allocate and initialize them all in the application delegate (I think these go in the applicationDidFinishLaunching method, but I'm not at my computer to verify that is the best place). You may want to set their isHidden property to YES (except for the one you want to show first).
Once they are loaded this way, the applications view controller can be used to change the hidden property when you want a view to show or be hidden.
If each view really takes 10 seconds to load, you will have an initial load time when the application starts that is 10 seconds times the number of views you are loading. But once they are loaded, you shouldn't have that delay anymore.
Update:
If you want to animate the transitions from one view to another, you will have to use more than the isHidden property (that can't be animated). But you can deal with that later, and still start off by allocating and initializing like I described above.
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.