这是我在 stackoverflow 上的第一篇文章,所以我会尽量讲清楚。我是 iPhone 开发的初学者,所以如果我的问题是菜鸟,请提前原谅。请原谅我的英语也...
我试图在 UIViewController 出现时立即在一些 UITextLabel 中显示日期值。但是 dateLabel 和 hourLabel 不会更新。仅当我在超级初始化之后放置断点时,代码才能正常执行。
调用 UIViewController CustomDatePicker
- (IBAction)setStartPointClicked:(id)sender {
_picker = [[CustomDatePicker alloc]initWithNibName:@"CustomDatePicker" bundle:nil];
_picker.delegate = self;
[self presentViewController:_picker animated:YES completion:^{
}] ;
}
调用 iniWithNibName 方法来初始化控制器
- (id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if(!self) { //<=============Breakpoint
return nil;
}
[self.datePicker addTarget:self action:@selector(dateChanged:) forControlEvents:UIControlEventValueChanged];
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd/MM/yyyy"];
NSString* str = [dateFormatter stringFromDate:_datePicker.date];
[_dateLabel setText:str];
NSLog(str);
[dateFormatter setDateFormat:@"HH:mm"];
str = [dateFormatter stringFromDate:_datePicker.date];
[_hourLabel setText:str];
NSLog(str);
return self;
}
我想我正在尝试在它们有时间分配之前调用属性。如果我在每个标签字符串更改后放置断点,它不会更新。仅当断点位于超级初始化和要执行的代码之间时,它们才会执行。断点是否给我的应用程序一些时间来加载对象?
有任何想法吗?提前致谢