objective-c - UITextField.text 一直返回 null

标签 objective-c ios ios5 uiviewcontroller

我已经为这个 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/

相关文章:

iphone - UITableViewCell 编辑缩进

ios - UITableviewCell 高度未在滚动时重置

ios - 当用户终止应用程序时,我可以进行 api 调用吗?

iphone - 我正在尝试使用 MWFeedParser 显示 MBProgressHUD 的进度

ios - 如何从 UIImagePickerController 选择多个图像

ios - 存储自定义类 iOS 8 核心数据

ios - 使用 RESTKit 映射带有括号的 JSON 响应

ios - (Swift) 为键盘移动 View ?

ios - 以编程方式获取应用程序支持文件夹的路径

iphone - FBWebDialogs presentRequestsDialogModallyWithSession 不工作?