Question

Is it possible to make the title of a UIAlertView get transfered into a UITextField that is in another view when the clickedButtonAtIndex button leads to that view?

So, a UITableViewCell opens the alertview when clicked, and the alertview has two buttons: Close and Next Screen. When Next Screen is pushed, another view opens, and in that view should be a UITextField that already has the title of the UIAlertView in it after the view loads (in viewDidLoad). Can anybody help?

Was it helpful?

Solution

You can simply ask the alert view for its title, and pass that to the next view controller. In the next view controller's viewDidLoad, it can put the title in the text field.

// In the view controller responsible for the alert view:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    NextViewController *vc = [[NextViewController alloc] init];
    vc.titleForTextField = alertView.title;
    [self presentViewController:vc animated:YES completion:nil];
}

// In NextViewController:
- (void)viewDidLoad {
    [super viewDidLoad];
    self.textField.text = self.titleForTextField;
}

(You'll need to give NextViewController a titleForTextField property.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top