theNewCat
theNewCat

Reputation: 1

Changing the title of a UIButton from a UILabel or UITextFiled

I need to know change the title of a UIButton from a UILabel or UITextFiled. For example, If I enter text into a UITextField and tap a button that says "enter" or something similar, another button's title will change to the text in the text field. Another example if I enter text into a text field and click "enter" in one view controller and click "next" to go to another view controller, a button in the later view controller will have the title of the text in the text field from the previous view controller. I currently don't have code to show what I have becasue nothing I have found has helped me at all. Any ideas would be greatly appreciated.

Upvotes: 0

Views: 287

Answers (2)

Wagh
Wagh

Reputation: 2688

Try this

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
  // get the instance of your button
    if(textField.tag == matchedTag){
     [[button titleLabel] setText:@"xyz"];  // or below call 
     [button setTitle:@"xyz" forState:UIControlStateNormal];
   }
}

Upvotes: 0

Zhang
Zhang

Reputation: 11607

Well, here's a stab:

// --------------------------------------------------------------------
// When user taps on your enter button in your first view controller
// --------------------------------------------------------------------
-(void)enterButtonPressed
{
    ViewController2 *vc2 = [[ViewController2 alloc] init];

    // set the button title in your second view controller
    [vc2.otherButton setTitle:self.textField.text forState:UIControlStateNormal];

    // show second view controller
    [self.navigationController pushViewController:vc2 animated:YES];
}

Upvotes: 1

Related Questions