Iphone:分割以逗号分隔的字符串并在pickerview的行中打印每个字符串
我得到一个字符串 mild,medium,hot
。我用逗号作为分隔符分割字符串。我也需要在 pickerView 中打印它。
我使用以下代码并成功将列表计数设置为 3。
NSString *spList=[mdict objectForKey:@"spicinesstype"];
NSArray *list = [spList componentsSeparatedByString:@","];
NSLog(@"List count:%d",[list count]);
return [list count];
但是我怎样才能在pickerview中显示所有3个项目
I got a string as mild,medium,hot
.I split the string with comma as separator.I need to print it in a pickerView too.
I used the following code and got List count as 3 successfully.
NSString *spList=[mdict objectForKey:@"spicinesstype"];
NSArray *list = [spList componentsSeparatedByString:@","];
NSLog(@"List count:%d",[list count]);
return [list count];
But how could I display all 3 items in pickerview
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该将您的类设置为选择器视图的委托,然后为您的选择器实现这 3 个委托方法
You should set your class as the delegate of the picker view, Then implement these 3 delegate methods for your picker
首先,您需要通过将 UIPickerViewDelegate 和 UIPickerViewDataSource 放在视图控制器头文件的 @interface 行的末尾来实现它们。
像这样:
@interface MyViewController : UIViewController
接下来,您需要将视图控制器设置为选取器视图的委托和数据源。您可以在视图控制器的
- (void)viewDidLoad
方法中添加以下行来执行此操作:或者,如果您正在使用 Interface Builder,则可以在 Interface Builder 中将其链接起来。
然后您需要在视图控制器源文件中实现这些委托方法。
First you need to implement UIPickerViewDelegate and UIPickerViewDataSource by putting them on the end of the @interface line of the header file of your view controller.
Like this:
@interface MyViewController : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource>
Next you need to set your view controller as the delegate and data source of you picker view. You can either do this in the
- (void)viewDidLoad
method of your view controller by adding the lines:Or you can link it up in Interface Builder if you are using that.
Then you need to implement these delegate methods in your View Controller source file.