Ios 从调用者视图设置UITextField的文本
我在一个视图上有一个条形码扫描仪,在用户扫描完条形码后,应用程序会将他们带到另一个视图(BoilerDetails),其中条形码文本字段已预先填充 我知道viewcontroller未进入视图时为空,并且我无法直接更改UITextField文本。到目前为止,这给了我一个错误。。我怎样才能解决这个问题 条形码扫描神经控制器.mIos 从调用者视图设置UITextField的文本,ios,objective-c,uiviewcontroller,Ios,Objective C,Uiviewcontroller,我在一个视图上有一个条形码扫描仪,在用户扫描完条形码后,应用程序会将他们带到另一个视图(BoilerDetails),其中条形码文本字段已预先填充 我知道viewcontroller未进入视图时为空,并且我无法直接更改UITextField文本。到目前为止,这给了我一个错误。。我怎样才能解决这个问题 条形码扫描神经控制器.m BoilerDetailsViewController *viewCtrl = [[BoilerDetailsViewController alloc] initWithN
BoilerDetailsViewController *viewCtrl = [[BoilerDetailsViewController alloc] initWithNibName:nil bundle:nil];
[viewCtrl setBarcode:strBarcode];
[self.navigationController pushViewController:viewCtrl animated:YES];
-(void)setBarcode:(NSString *)strBarcode
{
self.barcode = strBarcode;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[_barcodeField setText:self.barcode];
// Do any additional setup after loading the view from its nib.
}
BoilerDetailsViewController.h
@interface BoilerDetailsViewController : SubViewControllerBase
@property (retain, nonatomic) NSString *barcode;
@property (retain, nonatomic) IBOutlet UITextField *barcodeField;
- (void)setBarcode:(NSString*)strBarcode;
@end
BoilerDetailsViewController.m
BoilerDetailsViewController *viewCtrl = [[BoilerDetailsViewController alloc] initWithNibName:nil bundle:nil];
[viewCtrl setBarcode:strBarcode];
[self.navigationController pushViewController:viewCtrl animated:YES];
-(void)setBarcode:(NSString *)strBarcode
{
self.barcode = strBarcode;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[_barcodeField setText:self.barcode];
// Do any additional setup after loading the view from its nib.
}
我认为这些字符串给了你无限的循环。根据您的逻辑,您应该使用:
-(void)setBarcode:(NSString *)strBarcode
{
self.barcodeField.text = strBarcode;
}
或
取决于您想要的内容(存储字符串或设置标签)。您只需合成
条形码
,然后在ViewDidload中编写此代码[\u barcodeField setText:barcode]代码>很好。首先,这是错误的
-(void)setBarcode:(NSString *)strBarcode
{
self.barcode = strBarcode;
}
self.barcode=strBarcode
本身调用setter
根据您的ios版本,您应该编写:
//for ARC environment
-(void)setBarcode:(NSString *)strBarcode
{
_barcode = strBarcode;
}
//since default association in ARC is strong
在此之前,请执行@合成条形码=\u条形码代码>
//and for non-ARC environment, since your property is retain type
-(void)setBarcode:(NSString *)strBarcode
{
if (_barcode != barcode) {
[_barcode release];
_barcode = [barcode retain];
}
}
你会没事的。添加self.barcodeField.text=strBarcode
内部-setBarcode:
方法