繁体   English   中英

如何在iOS中的UITextField设置默认文本

[英]How to set default text at UITextField in iOS

以下是我的代码:

- (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;
}

我从另一个viewController获得这些值,我想用上述值设置这些textFields。 有人可以帮忙吗? 我是iOS新手。

我正在调用上述方法的方法:

-(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];
}

您的代码应在以下情况下工作:

  • 文本字段在Interface Builder中连接或通过编程正确初始化。
  • 您可以在主线程中设置这些属性。

您应该检查以下几件事,如果其中一种是事实,也可能是全部,则您的代码将不起作用:

  • 文本字段应链接到其IBoutlets ,即self.textFieldAge不应为nil
  • 另外,您正在调用getAge此函数的对象或视图控制器,请检查该对象是否不是nil

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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