我正在编写像
这样的代码- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
int n=row+1;
if(row == 0)
return [NSString stringWithFormat:@"%d minute", n];
return [NSString stringWithFormat:@"%d minutes", n];
}
现在我想启动计时器,因为我选择了任何一行,就像第5行有5分钟,所以我想用5分钟启动计时器,所以我该怎么办,如何选择特定的行并按下按钮并启动计时器对于那个事件?
答案 0 :(得分:2)
将来如果你进入谷歌并输入你的班级名称和“课堂参考”,你通常可以在苹果网站上找到你需要的信息。
例如,我刚进入谷歌并输入“UIPickerView类引用”并进入此处:http://developer.apple.com/library/ios/#documentation/uikit/reference/UIPickerView_Class/Reference/UIPickerView.html。
在该网站上,如果您阅读说明“委托必须采用UIPickerViewDelegate协议”,如果您点击它,则说明在任务下:
pickerView:didSelectRow:inComponent:
这是您需要实现的委托方法,当用户选择行时将调用该方法。如果你点击它就会给出一些描述等等。
如果你去描述那么完整的方法是:
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
因此,当用户选择一行时,将调用此方法,并自动将pickerView传递给该方法。
然后,您可以获取用户选择的行。如果您将页面返回到UIPickerView类引用,您会看到:
– selectRow:inComponent:animated:
– selectedRowInComponent:
方法selectedRowInComponent:
是您想要的方法。所以在委托方法中你可以这样做:
int selectedRow = (int)[pickerView selectedRowInComponent:0];
:)当我想找到这样的问题的答案时,这就是我的工作。 :)
编辑:
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
int selectedRow = (int)[pickerView selectedRowInComponent:0];
NSLog(@"%i",selectedRow);
}
答案 1 :(得分:0)
假设您已实现UIPickerViewDelegate协议,这是Thomas Clayson的答案的Swift 5版本:
from pyspark.sql.functions import *
from pyspark.sql.functions import rand
from pyspark.sql.types import *
from pyspark.sql import SparkSession
from pyspark.sql import DataFrame