如何为UIPickerView使用selectedRowInComponent方法

ter*_*333 1 iphone

我有一个UIPickerView对象,有五行供用户选择.我想返回用户在IBAction上选择的行的索引.当我的方法被调用时,我可以返回用户使用此代码选择的值的文本: NSString * userChoice = [self pickerView:picker titleForRow:[picker selectedRowInComponent:0] forComponent:0]; 我现在想要作为NSInteger返回,返回的行.以下代码杀死了程序,我不知道为什么: NSLog(@"hello?? %@", [picker selectedRowInComponent:0]);

有什么想法吗??除了selectedRowInComponent之外还有更好的方法吗?

Aar*_*ers 6

试试这个

NSLog(@"hello?? %d", [picker selectedRowInComponent:0]);
Run Code Online (Sandbox Code Playgroud)