I'm currently working on an app that needs to support iOS6 and iOS7.
I'm creating an alert like this:
self.newCategoryAlertView = [[[UIAlertView alloc] initWithTitle:NSLocalizedString(#"MessageTitleNewCategory", nil)
message:NSLocalizedString(#"MessageTextNewCategory", nil)
delegate:self
cancelButtonTitle:nil
otherButtonTitles:NSLocalizedString(#"ButtonOK", nil), NSLocalizedString(#"ButtonCancel", nil), nil] autorelease];
self.newCategoryAlertView.cancelButtonIndex = 1;
self.newCategoryAlertView.tag = alertViewTypeNewCategory;
self.newCategoryAlertView.alertViewStyle = UIAlertViewStylePlainTextInput;
[self.newCategoryAlertView textFieldAtIndex:0].delegate = self;
[self.newCategoryAlertView textFieldAtIndex:0].autocapitalizationType = UITextAutocapitalizationTypeSentences;
[[self.newCategoryAlertView textFieldAtIndex:0] setReturnKeyType:UIReturnKeyDone];
[[self.newCategoryAlertView textFieldAtIndex:0] setKeyboardAppearance:UIKeyboardAppearanceDefault];
[self.newCategoryAlertView textFieldAtIndex:0].enablesReturnKeyAutomatically = YES;
[self.newCategoryAlertView show];
In the delegate I'm implementing the following protocol method
- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
{
if(alertView.tag == alertViewTypeNewCategory)
{
UITextField *textField = [alertView textFieldAtIndex:0];
if (!textField.text || [textField.text isEqualToString:#""])
{
return NO;
} else {
return YES;
}
} else {
return YES;
}
}
My problem is that the left button is disabled running on iOS6 (as expected), but when running on iOS7 the right button is disabled.
I checked the values of cancelButtonIndex and firstOtherButtonIndex inside the delegate method and they are the same in iOS7 and iOS6.
Any hints what I'm doing wrong? Or a workaround to fix this behaviour?
Its seems like iOS 7 has changed arranging order for buttons as per indexes.
I have tried your code and added few more buttons to check arranging order.
[[UIAlertView alloc] initWithTitle:NSLocalizedString(#"MessageTitleNewCategory", nil)
message:NSLocalizedString(#"MessageTextNewCategory", nil)
delegate:self
cancelButtonTitle:nil
otherButtonTitles:NSLocalizedString(#"ButtonOK", nil), NSLocalizedString(#"ButtonCancel", nil),NSLocalizedString(#"Third Button", nil),NSLocalizedString(#"Fourth Button", nil),NSLocalizedString(#"Fifth Button", nil), nil];
For UIAlertView in iOS 7
First button "ButtonOK" is at the top but second button is at the last position and rest buttons placed ascending order same as previous iOS versions.
So, you can check iOS version using [[UIDevice currentDevice] systemVersion] and do
if (iOS 7) {
self.newCategoryAlertView = [[[UIAlertView alloc] initWithTitle:NSLocalizedString(#"MessageTitleNewCategory", nil)
message:NSLocalizedString(#"MessageTextNewCategory", nil)
delegate:self
cancelButtonTitle:nil
otherButtonTitles:NSLocalizedString(#"ButtonCancel", nil),NSLocalizedString(#"ButtonOK", nil), , nil] autorelease];
}else{
self.newCategoryAlertView = [[[UIAlertView alloc] initWithTitle:NSLocalizedString(#"MessageTitleNewCategory", nil)
message:NSLocalizedString(#"MessageTextNewCategory", nil)
delegate:self
cancelButtonTitle:nil
otherButtonTitles:NSLocalizedString(#"ButtonOK", nil), NSLocalizedString(#"ButtonCancel", nil), nil] autorelease];
}
Related
I have done a photoEditorApp, which is in AppStore. Now i want to apply InApppurchage for some Buttons only. In my App overlays button is there when we click that button we are getting 7 buttons in which 3 buttons for free remaining 4 buttons for purchase .for that i have written code like this .but its not working don't know where i did mistake so please anyone suggest how to do UIScrollView *scrollView;
-(void)createScrolling2
{
previousButtonTag=1000;
if (UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad) {
scrollView=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 4, self.overlaysView.frame.size.width, 106)];
int x =0.5;
for (int i = 0; i<8; i++) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame=CGRectMake(x, 0, 100, 100);
button.layer.borderWidth=0.5;
button.titleLabel.font=[UIFont boldSystemFontOfSize:12];
button.titleLabel.textAlignment = NSTextAlignmentCenter;
button.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
button.layer.borderColor=[[UIColor lightGrayColor]CGColor];
button.tag = i;
if (subButtonTag == 101) {
[button setBackgroundImage:[self.fireworksArray objectAtIndex:i] forState:UIControlStateNormal];
}
else if (subButtonTag == 102){
[button setBackgroundImage:[self.flowersArray objectAtIndex:i] forState:UIControlStateNormal];
}
else if (subButtonTag == 103){
[button setBackgroundImage:[self.loveArray objectAtIndex:i] forState:UIControlStateNormal];
}
else if (subButtonTag == 104){
[button setBackgroundImage:[self.rainbowArray objectAtIndex:i] forState:UIControlStateNormal];
}
int previousButtonTag;
-(void)OverLayMethod:(UIButton*)sender{
UIButton *selectButton = (UIButton*)sender;
NSLog(#"hi %d",sender.tag);
previousButtonTag=selectButton.tag;
NSLog(#"hi %d",sender.tag);
UIImage *selectImage;
if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone){
if (subButtonTag == 101) {
selectImage = [self.fireworksArray objectAtIndex:sender.tag];
NSLog(#"selectImage = %#",selectImage);
self.overlayImgView.image = selectImage;
}
else if (subButtonTag == 102){
selectImage = [self.flowersArray objectAtIndex:sender.tag];
NSLog(#"selectImage = %#",selectImage);
self.overlayImgView.image = selectImage;
}
else if (subButtonTag == 103){
selectImage = [self.loveArray objectAtIndex:sender.tag];
NSLog(#"selectImage = %#",selectImage);
self.overlayImgView.image = selectImage;
}
else if (subButtonTag == 104){
selectImage = [self.rainbowArray objectAtIndex:sender.tag];
NSLog(#"selectImage = %#",selectImage);
self.overlayImgView.image = selectImage;
}
- (IBAction)buyPackClicked:(id)sender
{
if (![demoPurchase restorePurchase])
{
UIAlertView *settingsAlert = [[UIAlertView alloc] initWithTitle:#"Allow Purchases" message:#"You must first enable In-App Purchase in your iOS Settings before restoring a previous purchase." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[settingsAlert show];
}
}
- (IBAction)restorePreviousClicked:(id)sender
{
if (demoPurchase.validProduct != nil)
{
if (![demoPurchase purchaseProduct:demoPurchase.validProduct])
{
UIAlertView *settingsAlert = [[UIAlertView alloc] initWithTitle:#"Allow Purchases" message:#"You must first enable In-App Purchase in your iOS Settings before making this purchase." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[settingsAlert show];
}
}
}
-(void) requestedProduct:(EBPurchase*)ebp identifier:(NSString*)productId name:(NSString*)productName price:(NSString*)productPrice description:(NSString*)productDescription
{
SKProduct *product = ebp.validProduct; // epb is the EBPurchase object
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[numberFormatter setLocale:product.priceLocale];
NSString *formattedPrice = [numberFormatter stringFromNumber:product.price];
NSLog(#"ViewController requestedProduct %#",productPrice);
if (productPrice != nil)
{
[buyPack setTitle:[#"Buy Pack item " stringByAppendingString:productPrice] forState:UIControlStateNormal];
buyPack.enabled = YES; // Enable buy button.
}
else {
buyPack.enabled = NO; // Ensure buy button stays disabled.
[buyPack setTitle:#"Buy Pack item" forState:UIControlStateNormal];
UIAlertView *unavailAlert = [[UIAlertView alloc] initWithTitle:#"Not Available" message:#"This In-App Purchase item is not available in the App Store at this time. Please try again later." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[unavailAlert show];
}
}
-(void) successfulPurchase:(EBPurchase*)ebp restored:(bool)isRestore identifier:(NSString*)productId receipt:(NSData*)transactionReceipt
{
NSLog(#"ViewController successfulPurchase");
if (!isPurchased)
{
isPurchased = YES;
NSString *alertMessage;
if (isRestore) {
alertMessage = #"Your purchase was restored and the Game Levels Pack is now unlocked for your enjoyment!";
} else {
alertMessage = #"Your purchase was successful and the Game Levels Pack is now unlocked for your enjoyment!";
}
UIAlertView *updatedAlert = [[UIAlertView alloc] initWithTitle:#"Thank You!" message:alertMessage delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[updatedAlert show];
}
}
-(void) failedPurchase:(EBPurchase*)ebp error:(NSInteger)errorCode message:(NSString*)errorMessage
{
NSLog(#"ViewController failedPurchase");
UIAlertView *failedAlert = [[UIAlertView alloc] initWithTitle:#"Purchase Stopped" message:#"Either you cancelled the request or Apple reported a transaction error. Please try again later, or contact the app's customer support for assistance." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[failedAlert show];
}
-(void) incompleteRestore:(EBPurchase*)ebp
{
NSLog(#"ViewController incompleteRestore");
UIAlertView *restoreAlert = [[UIAlertView alloc] initWithTitle:#"Restore Issue" message:#"A prior purchase transaction could not be found. To restore the purchased product, tap the Buy button. Paid customers will NOT be charged again, but the purchase will be restored." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[restoreAlert show];
}
-(void) failedRestore:(EBPurchase*)ebp error:(NSInteger)errorCode message:(NSString*)errorMessage
{
NSLog(#"ViewController failedRestore");
UIAlertView *failedAlert = [[UIAlertView alloc] initWithTitle:#"Restore Stopped" message:#"Either you cancelled the request or your prior purchase could not be restored. Please try again later, or contact the app's customer support for assistance." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[failedAlert show];
}
Here when I want to click any button in that 4 buttons getting alert for buy diaplying cost.
I have an app that uses a UIAlertViewStyleLoginAndPasswordInput alert view. Everything works fine with the exception that the password field's placeholder text has some strange behavior. On my sim it refuses to change from 'Password' regardless of what I set it as. And Ive been having reports that it flip flops between 'Password" and the value I wish to set it at. This seems to be all iOS7 related.
I am attempting to set these values in the 'willPresentAlertView' delegate.
- (void)willPresentAlertView:(UIAlertView *)alertView
{
...
else if (alertView.tag == UIAlertViewTagInactivityTimeOut)
{
badgeNumberTextField = [alertView textFieldAtIndex:0];
verifyBadgeNumberTextField = [alertView textFieldAtIndex:1];
[badgeNumberTextField setPlaceholder:#"Badge Number"];
[verifyBadgeNumberTextField setPlaceholder:#"Verify Badge Number"];
[verifyBadgeNumberTextField setSecureTextEntry:NO];
[badgeNumberTextField setFont:[UIFont systemFontOfSize:ALERT_VIEW_TEXTFIELD_TEXT_FONT]];
[verifyBadgeNumberTextField setFont:[UIFont systemFontOfSize:ALERT_VIEW_TEXTFIELD_TEXT_FONT]];
[badgeNumberTextField setKeyboardType:UIKeyboardTypeNamePhonePad];
[verifyBadgeNumberTextField setKeyboardType:UIKeyboardTypeNamePhonePad];
[badgeNumberTextField setClearButtonMode:UITextFieldViewModeWhileEditing];
[verifyBadgeNumberTextField setClearButtonMode:UITextFieldViewModeWhileEditing];
[badgeNumberTextField setDelegate:self];
[verifyBadgeNumberTextField setDelegate:self];
...
//other code
}
}
Have you tried set the placeholder where you create the UIAlertView?
Try this:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Title" message:#"Message" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Login", nil];
alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
[alert textFieldAtIndex:0].placeholder = #"Username placeholder";
[alert textFieldAtIndex:1].placeholder = #"Password placeholder";
[alert show];
I have a UILongPressGestureRecognizer added to a UITextField. When I press the UITextField it is show me alert but that is three alert show me.
That is my code:
- (void)viewDidLoad
{
[super viewDidLoad];
UILongPressGestureRecognizer *gs = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:#selector(AlertServer:)];
gs.delegate = self;
[_companyidTxt addGestureRecognizer:gs];
[gs release];
}
-(void)AlertServer:(UILongPressGestureRecognizer *)gs
{
alertView = [[UIAlertView alloc] initWithTitle:#"Server" message:#"" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Okay", nil];
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
myTextField = [alertView textFieldAtIndex:0];
myTextField.text=mainString;
[alertView show];
[alertView release];
[alertView retain];
}
Can anyone explain why this happens, and how it can be prevented?
Thanx in advance
Try this,
- (void)AlertServer:(UILongPressGestureRecognizer*)sender {
if (sender.state == UIGestureRecognizerStateEnded) {
alertView = [[UIAlertView alloc] initWithTitle:#"Server" message:#"" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Okay", nil];
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
myTextField = [alertView textFieldAtIndex:0];
myTextField.text=mainString;
[alertView show];
[alertView release];
}
else if (sender.state == UIGestureRecognizerStateBegan){
NSLog(#"UIGestureRecognizerStateBegan.");
//Do Whatever You want on Began of Gesture
}
}
Change your longPressGestureRecognizer.minimumPressDuration based on your observations (The time interval is in seconds. The default duration is is 0.5 seconds.) or use some flag to check if Alert is already shown.
My application only supports landscape, and I'm having an issue only on the iPhone in iOS6 where the Game Center Leaderboard is the wrong orientation and partially off the screen. See attached:
I'm calling a modal UITableView from my view controller using an FPPopover like this:
HighScoresController *controller = [[HighScoresController alloc] init];
FPPopoverController *popover = [[FPPopoverController alloc] initWithViewController:controller];
popover.arrowDirection = FPPopoverNoArrow;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
popover.contentSize = CGSizeMake(350,450);
else
popover.contentSize = CGSizeMake(350,350);
popover.delegate = self;
popover.title = #"High Scores";
[popover presentPopoverFromPoint: CGPointMake(mainView.center.x, self.view.center.y + 50)];
Then when one of the rows are clicked on this table, it calls the appropriate leaderboard in Game Center:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// authenticate into game center
[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error){
if (error ==nil) {
GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
if (leaderboardController != nil)
{
leaderboardController.leaderboardDelegate = self;
leaderboardController.timeScope = GKLeaderboardTimeScopeAllTime;
leaderboardController.category = [leaderboardIDs objectAtIndex:[indexPath row]];
[self presentViewController: leaderboardController animated: YES completion:nil];
}
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Game Center"
message:#"You need to sign into Game Center in order to view high scores" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"OK", nil];
[alert show];
}
}];
}
Any ideas on how to fix this issue? It's fine on iOS 5 with iPhone, as well as iPad for both iOS 5 and 6.
Thanks!
I have a button which I want to implement with password before triggering a segue if the password is correct. it all looks fine up to the moment when you type in wrong password and I have implemented another alertView to tell the user the password is wrong. When the alert view pops out and dismisses after some delay, it keeps re-appearing and disappearing and nothing else can be done on the screen!
How to stop the re appearing?
Below is my part of the code that deals with this:
- (IBAction)editLeagues:(id)sender {
[self presentAlertViewForPassword];
}
-(void)presentAlertViewForPassword
{
_passwordAlert = [[UIAlertView alloc]initWithTitle:#"Password"
message:#"Enter Password to edit Leagues"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"OK", nil];
[_passwordAlert setAlertViewStyle:UIAlertViewStyleSecureTextInput];
_passwordField = [_passwordAlert textFieldAtIndex:0];
_passwordField.delegate = self;
_passwordField.autocapitalizationType = UITextAutocapitalizationTypeWords;
_passwordField.tag = textFieldPassword;
[_passwordAlert show];
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSString *password = [NSString stringWithFormat:#"55555"];
if ( ![_passwordField.text isEqual:password]) {
_wrongPassword = [[UIAlertView alloc] initWithTitle:#"Wrong Password"
message:#"You are not authorised to use this feature!"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:nil];
[_wrongPassword show];
[self performSelector:#selector(allertViewDelayedDissmiss:) withObject:nil afterDelay:2];
}
else
{
[self performSegueWithIdentifier:#"addLeague" sender:[alertView buttonTitleAtIndex:0]];
}
}
-(void) allertViewDelayedDissmiss:(UIAlertView *)alertView
{
[_wrongPassword dismissWithClickedButtonIndex:-1 animated:YES];
}
- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
{
NSString *inputText = [[alertView textFieldAtIndex:0] text];
if( [inputText length] >= 4 )
{
return YES;
}
else
{
return NO;
}
}
[_wrongPassword dismissWithClickedButtonIndex:-1 animated:YES]; will call the delegate method alertView:didDismissWithButtonIndex:
You have two options:
don't set a delegate on the wrong password alert
check for the correct alert in alertView:didDismissWithButtonIndex: e.g.
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (alert == _passwordAlert) {
NSString *password = [NSString stringWithFormat:#"55555"];
// and so on
}
}
Issue is causing because when you dismiss the wrong password alert it'll also call the didDismissWithButtonIndex delegate method.
Solution 1
Set the delegate of wrong password alert to nil.
wrongPassword = [[UIAlertView alloc] initWithTitle:#"Wrong Password"
message:#"You are not authorised to use this feature!"
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:nil];
Solution 2
Add a tag to your alertView. And change your methods like:
-(void)presentAlertViewForPassword
{
_passwordAlert = [[UIAlertView alloc]initWithTitle:#"Password"
message:#"Enter Password to edit Leagues"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"OK", nil];
[_passwordAlert setAlertViewStyle:UIAlertViewStyleSecureTextInput];
passwordAlert.tag = 7;
_passwordField = [_passwordAlert textFieldAtIndex:0];
_passwordField.delegate = self;
_passwordField.autocapitalizationType = UITextAutocapitalizationTypeWords;
_passwordField.tag = textFieldPassword;
[_passwordAlert show];
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if(alertView.tag == 7)
{
NSString *password = [NSString stringWithFormat:#"55555"];
if ( ![_passwordField.text isEqual:password])
{
_wrongPassword = [[UIAlertView alloc] initWithTitle:#"Wrong Password"
message:#"You are not authorised to use this feature!"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:nil];
[_wrongPassword show];
[self performSelector:#selector(allertViewDelayedDissmiss:) withObject:nil afterDelay:2];
}
else
{
[self performSegueWithIdentifier:#"addLeague" sender:[alertView buttonTitleAtIndex:0]];
}
}
}