In my app, sometimes all the textfield 's copy&paste menu is missing when the user is tapping in the textfield.
But when the user kill the app and restart again, the function comes back.
Has anyone encountered this problem before?
I do not subclass UITextField, what could cause such problem?
Any advice would be greatly appreciated.
Thank you.
I have found that in on of my view controller, I used two alertViews. After the first alertView diss, I immediately pop up the second UIAlertView in the callback
- (void) alertView:(UIAlertView *) alertView clickedButtonAtIndexL(NSInteger) buttonIndex
{
//[thesecondalertview show];
}
Since the firstAlert view does not completely dimiss, pop up the second alertview it may cause the UIWindow disorder.
If we pop up the second UIAlertView in the first alertviews's callback,
- (void) alertview:(UIAlertView*)alertview didDissmissWithButtonIndex:(NSInteger) buttonIndex
the problem solved.
Related
I have a UITextField that the user enters their name into. When they tap a button, my app checks to make sure that they actually entered something. If they didn't I have an alert view come up stating so, and then below that I have this code:
[textField becomeFirstResponder];
The only problem is, when the user hits the ok button on the alert view, the text field does not become selected so that the user can enter text into it, instead they have to tap it manually, which defeats the purpose of the code. It's like the alert view is preventing this from happening. What do you suggest I do? Thanks for your help!
How do you show your alert? Do you call [textField becomeFirstResponder] right after the [alert show] ?
If so, that's the problem. You should register your controller as your alert's delegate, then call becomeFirstResponder when you receive the alertView:didDismissWithButtonIndex: message.
Take a look at the UIAlertViewDelegate protocol.
I have a UIAlertView with the following delegate method:
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex {
But I have a problem. In that method, I do some logic and perform some lines of code which take a small amount of time. I would like to dismiss the alertView before I do all of this. I want to dismiss the alert view at the very top of that method. That way, when the user taps a button on the alertView, the app doesn't seem frozen for a second while the next lines of code are executed.
To dismiss a alert programaticly do:
/* Your Processing Code Here */
[theAlertView dismissWithClickedButtonIndex:0 animated:YES];
The [theAlertView dismissWithClickedButtonIndex:0 animated:YES]; will make the alert go away
Either use the delegate method -alertView:didDismissWithButtonIndex: instead—it gets called once the alert view’s been removed from the screen, which will at least conceal the lag your app’s having—or, better, use a background thread, e.g. with -performSelectorInBackground:withObject:, to handle whatever processing you need to do.
Use the other delegate method for did, instead of will:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;
You should probably also execute the other lines of code you mention asynchronously, so as not to freeze the UI at all.
another probably simple iPhone obj-c question for you...
I have a couple of alerts which have buttons in them that are presented to the user in certain circumstances, both are part of one view. Now I know how to tell which button was pressed, but how do I know which alert the button pressed is related to?
Any ideas would be really handy! Cheers!
Set a tag to each of the alerts, and compare the tag of the alert caught at the delegate method didDismissWithButtonIndex.
Set tag as, alert.tag = 10;
and check in delegate as
if (alertView.tag == 10)
Try to implement a simple delgate for your alert views.
For exemple using : alertView:clickedButtonAtIndex:
you will be able to know which alert view the button pressed is related to.
You can call UIAlertView's Delegate method explained below...and check for title or alert message like this.. here i had given you the example of title...
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0 && [alertView.title isEqualToString:#"Invalid"])
{
//Your Stuff goes here
}
}
I am developing an iPhone application, in which I want to use customized alert sheet. The customization is required since I want to set image for Alert-Sheet buttons, change the size of these button etc.
I have done the following things:
Created UIView with customized controls that I wanted.
Created and displayed UIAlertView
In the delegate method of UIAlertView (UIAlertViewDelegate) i.e
- (void)willPresentAlertView:(UIAlertView *)alertView
I am removing all the subviews of UIAlertView and adding my customized view as subview.
Everything works fine till here. Since I have used customized buttons, I need to remove the alert sheet explicitly in the Action Method of the button by calling dismissWithClickedButtonIndex:animated: on UIAlertView.
Even though the UIALertView gets dismissed, it takes around 0.5 second to get dismissed.
Can someone help me out to solve the problem of this delay in dismissing OR some other way of customization of Alert View buttons.
Thanks and Regards,
Deepa
I could get it worked by passing YES to dismissWithClickedButtonIndex:animated: call i.e [alertView dismissWithClickedButtonIndex: 0 animated: YES]. Initially I was passing the flag as NO. But, I don't know whey it takes less time if we pass the animation flag as YES.
Anyone knows this?
Instead of doing this
/*
1. Created UIView with customized controls that I wanted.
2. Created and displayed UIAlertView
3. In the delegate method of UIAlertView (UIAlertViewDelegate)
*/
do this:
Create a class like this:
#interface CustomAlertView : UIAlertView
{
//For ex:
UIButton *myCustomButton;
//and other custom controls
}
Implement it in following method:
-(id)init
{
}
In the above method use:
[self addSubView: myCustomButton];
I have given just the idea. I have code but not presently to share with you.
If you are not able to implement the above I will provide later.
Thanks.
Here is the library which can solve your UIAlertView Customisation issue. It can also work as UIActionSheet. It has very good customisation options.
https://github.com/Codigami/CFAlertViewController
If learned the hard way that you should remove the delegate from an object if the life span of the delegate is shorter than the object. But how do you do this if you don't have a reference to the object anymore?
In my iPhone application I have a view controller vc which performs an asynchronous activity and is displayed as a modal view. A cancel button dismisses the modal view. If an error occurs, an UIAlertView alert is displayed. If the user taps on ok, both alert and the modal view disappear. Therefore vc is set
as delegate for alert and implements alertView:didDismissWithButtonIndex:. Something like this:
// UIViewController vc
...
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"Error"
message:#"Something went wrong"
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
self.alertView = alert; // needed to unset alertView.delegate in dealloc
[alert show];
[alert release];
...
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
[self dismissModalViewControllerAnimated:YES];
}
}
Normally, the alert view blocks all input. Unfortunately, it fails to do so in some edge cases.
If the user touches down on the cancel-button before the alert view appears and touches up after the alert view appears, the view is dismissed, but not the alert. vc gets deallocated and if the user then taps "ok" on the alert, the application crashes because a message was sent to the released object.
I solved this by assigning alert to a property of vc so I can set alert.delegate to nil in dealloc. I find this solution to be not very elegant, because I don't really need the reference to alert.
Is there a better approach?
Edit: Added the text in italics as clarification
Although, normally an alert view is presented over non changing content. So if the delegate is alive when the view appears it will likely be alive when it's dismissed. If that's not the case, you have to do exactly what you did, and unset the alert view's delegate manually if you no longer care about it's result.
So you do care about the alertview since you care about it's delegate method. The wrinkle is that the delegate may not apply by the time the alert is dismissed. So you need logic there, and for that logic you need to save a reference to the alert view in question.
In other words, you are doing it right. Although, it may have been helpful if UIAlertView retained it's delegate, but it doesn't seem like it does if it crashes when it's dismissed.
Lastly, I thought alert view blocked all screen input? If not, you can make it truly modal by setting vc.view.userInteractionEnabled = NO when the alert appears and switch it back when it's dismissed. This way the user can't dismiss the controller while the alert view is up. Which sounds a bit more sane to me.
From a UI perspective, when an alert view is present, it should demand the user's full attention. Perhaps you might consider disabling the Cancel button (as well as any other visible non-alert-view widgets) when there is an alert view present, and adding a button title to the UIAlertView instance which performs the same task. This would provide a clearer user interface and should also neatly solve your memory issue.
-(void)delayedDismiss {
[self dismissModalViewControllerAnimated:YES];
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
[self performSelector:#selector(delayedDismiss) withObject:nil afterDelay:0.0];
}
If you no longer care about the results of the UIAlertView you should probably also dismiss it in the - (void) viewWillDisappear:(BOOL)animated