Copy and Paste sometimes don't appear in my UITextView - ios

I created an app with a UITextView and occasionally it won't show the Select, Copy, Paste menu items when I tap on text. If I double-tap the home button and close the app, then re-open it, I'm able to do it again, which makes me think it's a memory problem (if it doesn't have enough memory, it doesn't show the menu?)

The problem in my case is that I created a UIWindow to cover the main window. I gave that window a windowLevel of UIWindowLevelAlertView / 20, so that it would hover between the main window and alert views. However, occasionally, AlertViews upon releasing key window, would revert the key window to my cover, and not the main window, and that would invalidate the menu controller's ability to properly display itself over the UITextView that was sitting in the main window.

Related

Disable mouse dragging item on Storyboard designer

There are some overlapping items, let's say A and B. To be specific, A is a background image. On other GUI frameworks, setting a background image is easy, but it seems I have to place an ImageView to fill the view with a background image on the Storyboard.
When I am trying to drag B, often A is selected and moved. Can I "lock" A so that it will not move? I searched the web and found that on Document --> Lock, but setting it to "Localizable Properties" does not lock it. I could still drag it with mouse.
I believe you have to set Lock to All Properties. You can still select the object, and click+drag will move it -- but it snaps back into place when you release it.
Unfortunately, this locks - as expected - ALL properties, so you could not, for example, lock a label in-place while also editing its content.

How do I make the elements in my UIView responsive?

My goal is to create an alert that has three text fields, one taller than the others, and an image that, when tapped, allows the user to choose a picture to replace a set default one.
After unsuccessfully searching for a library for this, I decided to create my own alert by placing a UIView off the screen and, when prompted by a button, would zoom onto the screen; it consists of all the elements I require.
When I run the application, the view pops up correctly, but none of the elements on the view are responding to touch. I've checked that isUserInteractionEnabled for everything is turned on.
What's also odd is that when I keep the view on the screen (instead of placing it some distance away on Storyboard), all the elements work fine.
I'm assuming it had something to do with the animation. I tested it with a fade in instead of a displacement, and the result was the same - the elements were unresponsive.
In order for your elements to be responsive you have to link the action of you clicking them to your view's code. You can do this in a non-programmatic manner by ctrl-clicking your element on story-views and then dragging to the view controller. Then choose action instead of outlet, and choose when the action you want will be triggered (bottom part). Then insert your code in the viewController.
So I figured it out. I used the debug view hierarchy and saw that the alert was behind the elements behind it, even though it was still being shown (for some reason). I changed the zIndex of the UIView and it worked!

iOS Left menu by button using MMDrawerController

I got some troubles making button for open/close leftside menu.
I made a button, but I can not configure it correctly, because I can't recognize whether the left view is open. It can be opened by swipe(special MMDrawer method), so I can't use a regular BOOL variable lika 'isOpen'. Also, I find it difficult to find a property for left view status (open/close).
I was surprised, that noone had trouble like this.
You could use the openSide property of MMDrawerController.
The current open side of the drawer.
Note this value will change as soon as a pan gesture opens a drawer, or when a open/close animation is finished.
As soon as the left view is opened, the value should change to MMDrawerSideLeft.

iOS View Controller is only accepting touches in a certain portion of the window

I have a relatively simple dialog/popup style UIViewController that isn't behaving correctly. I have many others just like it (though each with a unique button layout) that work just fine. For some reason that I cannot figure out, this controller is only accepting touches within (approximately) the green shaded area.
Note that none of these colors are the actual colors, just placeholders. Same goes for the text.
Tapping in the "Search..." text field does nothing. Tapping on the "Cancel" button does nothing. No UI reaction whatsoever.
The tableview will scroll just fine (there are over 100 rows) if it's touched inside (approximately) the green region. Touching the tableview below the green results in no response. Same thing for the "Cats" button. It reacts when touched in approximately the top half, but nothing in the bottom half.
I've banged my head against the wall for the requisite "several hours" and am getting nowhere.
It seems that part of your view controller's view is overlapped with some "harmful" view/views. Maybe this view is created programmatically and is not visible in IB. You should start with checking your views hierarchy. Put breakpoint in your view controller's code. Somewhere, where you are sure all views (normal and harmful) are already created and type in debug area
po [self.view recursiveDescription]
you should receive something like
Now try to find harmful views. Temporarily delete some "normal" views could be a good idea.
I found my solution. I have a method that launches a dialog controller given the dialog to launch and the parent (up until this point, always a full-screen view controller). The parent gets darkened and the dialog gets launched on the center of the screen.
This one wasn't working because I was launching it from an existing dialog; I was telling the dialog launcher that the new dialog's parent was the current dialog, not the whole screen. This means that the new dialog (which is bigger than the first one) launches at the correct size, but only accepts input inside the area of the "parent" dialog, which is the smaller one underneath it.
Fix: Launch the new dialog using the current dialog's parent (which is full screen) and it works fine. The green zone on my image is the approximate size of the dialog that was being used as the parent, which is why input was only being accepted in that area.

UIWebView freezes when text is selected

My app, on very rare occasions, freezes when I select text in a UIWebView. Here's how it happens:
Tap and hold to select text
Text gets selected
Whole app freezes, unresponsive to touch, but I can still see operatings running
May freeze for around 10s. After that the UIMenuController appears. If I try to scroll while it is freezing, the scrolling happens after the app is responsive again
If the text is still selected, it freezes again if I scroll. Happens again and again
If I managed to scroll the selected text out of the view, scrolling the rest of the webview is fine, until I scroll the selected text back
If I get out of the UIViewController containing the UIWebView, I can confirm that they are both deallocated. Go back into a new UIViewController with UIWebView and it happens again.
This continues to happen with new instances of UIWebView, and even when I close and resume the app. Only stops if I force a restart of the app.
Does anyone have any clue how I can debug this? I've never seen this in simulator. Only happens very rarely on device.
I suspect you either have set up your view hierarchy improperly, or have modified it on a thread not the main thread. So tell us exactly where the UIWebView resides (super views), and take a good look at code that modifies sub view arrays.
For instance, you don't add the web view to a UINavigationController's sub views directly, but to its view controllers array etc.
All else fails create a demo project that also displays the problem and upload it to DropBox where we can run it ourselves.

Resources