Objective-C:自动更新标签文本
我是 Objective-C 的新手,我需要你的帮助!在下面您将看到的代码中,我的标签从选取器视图中选取数据。我希望不使用“计算”IBAction,而是在用户更改选择器视图中的值时实时更新我的“chargeLabel.text”。
-(IBAction)calculate:(id)sender {
float floatTime;
if ([typeLabel.text isEqualToString:@"NiMH"])
{
floatTime=([mAhLabel.text floatValue]/chargerSlider.value)*1.5;
} else {
floatTime=([mAhLabel.text floatValue]/chargerSlider.value)*1.4;
}
int intHourhs=(floatTime);
float floatHours=(intHourhs);
float floatMinutes=(floatTime-floatHours)*60;
NSString *stringTotal = [NSString stringWithFormat: @"Hours: %.0i Minutes: %.0f", intHourhs, floatMinutes];
chargeLabel.text=stringTotal;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须实现 UIPickerViewDelegate 协议。
然后,在
didSelectRow
方法中执行您想要的操作检查 UIPickerViewDelegate 协议参考
编辑: 我刚刚意识到您的访问
chargerSlider
的value
属性,如果它是UISlider
,则不需要实现任何委托,只需将 IBAction 分配给Value更改了 IB 中滑块的选择器。
You have to implement
UIPickerViewDelegate
Protocol.Then, perform whatever you want in
didSelectRow
methodCheck UIPickerViewDelegate Protocol Reference
EDIT: I just realized that your accessing
value
property ofchargerSlider
if it is aUISlider
you don't need to implement any delegate, just assing your IBAction to theValue Changed
selector of the slider in IB.将自己设置为 UIPickerView 的委托,并实现此方法:
pickerView:didSelectRow:inComponent
调用此方法时,只需调用
[selfcalculate:nil];
Set yourself up as the delegate of UIPickerView, and implement this method:
pickerView:didSelectRow:inComponent
When this method get called, simply call
[self calculate:nil];