Let Say there was a working iPad app.
It has a TextField and a small button (arrow) at the end of the TextField. When ever the the small arrow is click, it should display the suggested options.(as UiPopOver)
The new requirement was , not only when the arrow button is clicked, even when the Textfield is touched, the popover should be shown over.
Method to show() in arrow button touchUpside event:
UIPopoverController activityPopover = [[UIPopoverController alloc] initWithContentViewController:activityViewController];
[activityPopover presentPopoverFromBarButtonItem:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
Method to hide():
[activityPopover dismissPopoverAnimated:YES];
What I did was very simple.
Added gestureevent to the text field and any single tap over it will trigger the arrow button click.
[button sendActionsForControlEvents:UIControlEventTouchUpInside];
but after adding the above piece of code, my app started crashing randomly.. I could not trace the pattern. I tried setting break point, but could not find anything. It just shows the interrupt SIGABRT and crashes. no log is written.
commenting the above code, it works fine.
I have no clue how to trace the issue.
Any help please?
I got similar situation in my case, because the button event got triggered two times, when touched over the button. Probably, both SingleTap gesture and the button tap event are triggered at same time, and try to disable UserIneraction over the button, and call the method associated directly, instead of triggering button event! I am not sure about this is the root cause. Am not a pro too!
Good Luck!
Related
I am implementing simple UI for URL checking. For this, I used textField and button objects.
When I run the program first time, textField and button will work fine but when I click on the done button on the keyboard then the keyboard is dismissed. Now I want to edit the textField and when I am trying to click on textField it is not clickable or not showing the keyboard. same thing happened to the button, next button is also not clickable.
Here is the code I wrote for the button action
- (IBAction)urlNextButtonAction:(id)sender {
[self.urlTextfield resignFirstResponder];
[SVProgressHUD showWithStatus:#"Verifying URL"];
[self URLValidationMethod];
}
Please check this video you will understand the problem very easily
This is the ViewController screenshot from storyboard
There could be several issue with this..
Check either Textfield delegate might not be or properly set.
Try to debug textfield delegate methods are they working.
it would be helpful if you show what you have written in keyboardShouldReturn method.
It seems like the problem is with the SVProgressHud. You should remove it as soon as you task is completed by calling [SVProgressHud dismiss] or else it will block the UI.
I am using Xcode to try to change my images position randomly every time a button is pushed but for some reason, the image only moves once in a while when the button is pushed even though I know it received the button's IBAction because the NSLog in the IBAction displayed in the console, I have tried it two ways and both methods only worked sporadically
Method 1:
ranX = arc4random() %320;
ranY = arc4random() %480;
myImage.center = CGPointMake(ranX, ranY);
Method 2:
myImage.center = CGPointMake(arc4random() %320, arc4random() %480);
One more thing: every time it does work, the next IBAction to run puts it right back into its original position.
More information that might be pertinent I don't know, I do not have size classes enabled, it is triggered by touch up inside. I also DID make all the RNGs arc4random_uniform.
The problem is fixed, just deselect auto layout.
What control event did you add to your button? Since you stated it moves every once in a while, you might have done the wrong event. Try UIControlEventTouchUpInside
So,
[myButton addTarget:self action:#selector(moveImage) forControlEvents:UIControlEventTouchUpInside];
You're using a storyboard I see, Make sure that the send event for the button is "Touch Up Inside". Click on the button, go to the Connections Inspector and double check this.
I have a few simple UIBarButtonsItems(no customization other than changing style, color and alpha). Everything was working perfectly fine for some time. But now I need to press BarButton for a long time(4-5 seconds) before the action is triggered. I just moved toolbar around and changed color and alpha after which this started happening. I don't exactly understand what caused this change of behavior.
I used interface builder to build the view and assigned action to UIBarButtonItems by Ctrl+Dragging.
I tried looking up a lot both on google and so. Most of the questions are about UIBarButtons not responding at all. Still I tried the solution of cleaning build of project and Xcode cache. But nothing changed.
Could someone help me with this?
I realized my mistake. I had two events getting triggered in same space in view. First was to reveal toolbar(i.e. increase its alpha) when tapped in particular area of the view and second one was of course button tap event for UIBarButtonItem. When tapped in that area the first event got triggered and eventually when pressed for long it also fired the second event once the toolbar was visible(if toolbar was invisible before).
Sorry to bother you all.
This is one of those "it was working a while ago" troubleshooting efforts.
I'm working on the document preview view controller, in which is a scroll view, which itself contains subclasses of UIView that represent each document. I'm modeling this pretty closely to how Keynote handles its document preview, except I build my scroll view horizontally and with paging. But the standard user experience is present: Long press on a document icon causes all document icons to start jiggling, nab bar has + button and Edit button, etc.
The issue at hand is that when you tap on the name of a document, I hide all the others, move the one being edited front and center, build a new text edit field, add it as a subview atop the real name label, and set it as first responder; but the
[editNameTextField setClearButtonMode:UITextFieldViewModeWhileEditing];
while correctly showing in the edit field is not taking any action when the user taps on the clear button.
I can't figure out what I may have done to cause this to not work -- it had been!
My first thought was that somehow my instance of this subclass is no longer the delegate for this text edit field. To try and confirm/deny that, I usurped a tap on the image view of the document preview to compare the delegate property to self, and it passes.
if (editNameTextField) {
NSLog(#"editNameTextField is still active");
if ([editNameTextField.delegate isEqual:self]) {
NSLog(#"we're still the delegate for the editNameTextField");
}
}
Editing the text within the edit field works fine. Pressing the Return/Done key correctly sends the delegate message textFieldShouldReturn:
While investigating this I implemented the delegate method textFieldShouldClear: just to write a log message if the method gets called (and return YES of course). It never gets called.
My next thought was that perhaps a subview had covered up the area where the clear button sits. So I implemented textFieldShouldBeginEditing: and used the opportunity to bring my the text field to the front. That didn't change anything either. I set a debugger breakpoint there to play a sound when it was called, and it got called, so I know my text edit field is frontmost.
I have only one troubleshooting strategy remaining: Go backwards through snap shots until it starts working again. Before doing that I thought I'd see if any of the more experienced folks out here have any suggestions of what to try next.
Where are you adding the textfield? As a subview of the scrollView? If you added the textfield and it is out of bounds of its parent view it won't receive any touches.
You can try and not call becomeFirstResponder and see if clicking it will show keyboard. Another possible error might be that the parent view of the UITextField has userInteractionEnabled = NO.
Without seeing more code I'm afraid I can not offer more solutions.
I made a simple IOS. application where the UI contains buttons. For example I have nine buttons each button represent a number same as numeric keyboard. I made this buttons the following way, put it to the storyboard and made the Touch Up Inside event with ctrl drag functions, after I copied the buttons eight times.
The problem is when I pressed a button the event comes sometimes twice. It happens randomly. I put a break point into line NSLog I did not see faulty thing at all.
- (IBAction)digitPressed:(UIButton *)sender {
if ([lastPressed isEqualToString:[sender currentTitle]]) {
NSLog(#"Douple pressed digit"); // break it here
}
// store to lastPressed
lastPressed = [sender currentTitle];
}
If you get multiple times in digitPressed when clicking once I would guess something went wrong when you copied the buttons so check the wiring in your storyboard.
And as Vince said it's a good practice to use id, it's not because this method gets triggered by buttons now that they should always be triggered by a button.
It's easier to debug when you log every time instead of only doubles.
NSLog(#"Button pressed: %#", [sender currentTitle]);