简体   繁体   中英

How to set default text at UITextField in iOS

Following is my code:

- (void)getAge:(NSString *)age getGender:(NSString *)gender  getLocation:(NSString *)location getPrefAge1:(NSString *)age1 getPrefAge2:(NSString *)age2 getPrefGender:(NSString *)prefGender getPrefLocation:(NSString *)prefLocation getImage:(UIImage *)image
{
    self.textFieldAge.text=age;
    self.textFieldGender.text=gender;
    self.textFieldLocation.text=location;
    self.textFieldPrefGender.text=prefGender;
    self.textFieldPrefAge1.text=age1;
    self.textFieldPrefAge2.text=age2;
    self.textFieldPrefLocation.text=prefLocation;

    self.imageProfilePic.image=image;
}

I get these value from another viewController I want to set these textFields with the above values. Can anyone help? I am new to iOS.

This the method where I am calling the above method :

-(IBAction)editpro:(id)sender
{
    ProfileEditViewController *profileEdit= [[ProfileEditViewController alloc] initWithNibName:@"ProfileEditViewController" bundle:nil];

    [profileEdit getAge:_labelAge.text getGender:_labelGender.text  getLocation:_labelLocation.text getPrefAge1:_labelPrefAge1.text getPrefAge2:_labelPrefAge2.text getPrefGender:_labelPrefGender.text getPrefLocation:_labelPrefLocation.text getImage:self.profilepic.image ];
    NSLog(@"Gender :%@",_labelGender.text);

    [profileEdit.saveProfile setHidden:YES];
    [self presentViewController:profileEdit animated:YES completion:nil];
}

Your code should work if:

  • Text fields are hooked up in Interface Builder or correctly initialized programmatically.
  • You set those properties in the main thread.

You should check the following things, your code will not work if one of these is the case or can be all too :

  • Text fields should be linked to their IBoutlets , that is self.textFieldAge should not be nil .
  • Also, the object or view controller you are calling this function of getAge , check if that object is not nil .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM