我已经为这个 UIViewController 创建了一个委托(delegate),我正在传递一个员工姓名来设置一个 UITextField。但是,无论我做什么,如您所见,结果都是 (null)。但是,我有一个以类似方式填充的日期标签,但它工作正常。我把它包括在内以供引用。我缺少一些简单的东西。但是,现在我眼睛都瞎了……
有什么想法吗?谢谢。
@interface TimesheetEntryViewController()
@property (weak, nonatomic) IBOutlet UILabel *datelabel;
@property (weak, nonatomic) IBOutlet UITextField *employeeTextField;
@end
@implementation TimesheetEntryViewController
@synthesize tableView = _tableView;
@synthesize datelabel = _datelabel;
@synthesize employeeName = _employeeName;
@synthesize employeeTextField = _employeeTextField;
-(void)setEmployeeNameString:(NSString *)lemployeeNameString
{
self.employeeTextField.text = lemployeeNameString;
NSLog(@"%@:%@", lemployeeNameString, self.employeeTextField.text);
}
结果:2012-05-02 08:42:50.137 rbTimesheet[7855:11303] Bob Smith:(null)
-(void)changeDateViewController:(ChooseDateViewController *)ntvc didChooseDate:(NSDate *)lDate
{
NSDateFormatter *df = [[NSDateFormatter alloc] init];
df.dateStyle = NSDateFormatterMediumStyle;
self.datelabel.text = [NSString stringWithFormat:@"%@",
[df stringFromDate:lDate]];
[self dismissModalViewControllerAnimated:YES];
}
最佳答案
我在 xcode 5 中通过拖放映射了文本字段,所以它没有合成,但我也尝试通过手动合成来解决这个问题,但没有成功。
我通过在 viewDidLoad 方法中的文本字段对象中分配空字符串解决了这个问题
_txtDialedNumber.text=@"";
注意:- 在使用它时我没有合成文本字段对象,它在 Xcode 5.0 中为我工作(在 iPhone 5 IOS 6 中测试)
关于objective-c - UITextField.text 一直返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10414174/