我有一个简单的小测试程序——两个标签和两个按钮。当您点击两个按钮中的任何一个时,顶部标签会显示相应按钮的 currentTitle 属性。第二个标签应该显示按钮被点击的时间,但在删除原始“标签”文本后显示为空白。
这两个 NSLog 语句按预期工作。
- (IBAction)buttonHit:(id)sender
{
DataClass *dataObject = [[DataClass alloc] init];
UIButton *resultButton = (UIButton *)sender;
dataObject.timeTapped = NSDate.date;
dataObject.nameTapped = resultButton.currentTitle;
self.nameLabel.text = dataObject.nameTapped;
NSString *timeOfHit = [[NSString alloc] init];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
timeOfHit = [formatter stringFromDate:dataObject.timeTapped];
self.timeLabel.text = timeOfHit;
NSLog(@"Button pressed was %@", dataObject.nameTapped);
NSLog(@"Time pressed was %@", dataObject.timeTapped);
}
所有帮助表示赞赏!
--蒂姆