Heena
Heena

Reputation: 2358

how to resign UIAlertview on textFileldShouldReturn?

I am having UIAlertview with UITextField in that.Mine is iPad application

-(void)showAlertToAddLink
{
    alertToAddLink =[[UIAlertView alloc] initWithTitle:@"" message:@"" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"ADD", nil];
    alertToAddLink.tag = 2;
    alertToAddLink.alertViewStyle = UIAlertViewStylePlainTextInput;
    [txtLinkName setDelegate:self];

    /*
    UITextField *txtLinkName = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 50.0, 260.0, 50.0)];
    [txtLinkName setDelegate:self];
//    txtLinkName.text=@"";
    [txtLinkName setFont:[UIFont fontWithName:@"Helvetica" size:17.0]];
    [txtLinkName setTextColor:[UIColor colorWithRed:71.0/255.0 green:78.0/255.0 blue:80.0/255.0 alpha:1]];
    [txtLinkName setBorderStyle:UITextBorderStyleRoundedRect];
    [txtLinkName setBackgroundColor:[UIColor whiteColor]];
    [txtLinkName setKeyboardAppearance:UIKeyboardAppearanceAlert];
    [txtLinkName setAutocorrectionType:UITextAutocorrectionTypeNo];
    [txtLinkName setAutocapitalizationType:UITextAutocapitalizationTypeNone];
    [txtLinkName setClearButtonMode:UITextFieldViewModeWhileEditing];
    [txtLinkName setTextAlignment:UITextAlignmentLeft];
   // [txtLinkName becomeFirstResponder];
    [alertToAddLink addSubview:txtLinkName];
    */[alertToAddLink show];

}

I tried with

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    [alertToAddLink resignFirstResponder];
    return YES;
}

But alertview is not being resig.

What is the way to do that

Upvotes: 0

Views: 573

Answers (1)

Aman Aggarwal
Aman Aggarwal

Reputation: 3754

Add this line to your textFieldShouldReturn:.

This will trigger dismissal of your alert view when textFieldShouldReturn: will be called:

 [alertToAddLink dismissWithClickedButtonIndex:alertToAddLink.cancelButtonIndex animated:YES];    

Hope it helps

Upvotes: 7

Related Questions