如何使用新数据重新加载选择器视图
我第一次使用存储在数组中的值加载选择器视图。
我正在使用,
temp = [NSArray arrayWithObjects:@"Male", @"Female", nil];
- (NSString *)pickerView:addData titleForRow:(NSInteger)row
forComponent:(NSInteger)component {
return [temp objectAtIndex:row];
}
但它显示空的选择器视图。
I am loading the picker view first time with the values which stored in array.
I am using,
temp = [NSArray arrayWithObjects:@"Male", @"Female", nil];
- (NSString *)pickerView:addData titleForRow:(NSInteger)row
forComponent:(NSInteger)component {
return [temp objectAtIndex:row];
}
But it shows the empty picker view.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您尝试过
[somePickerVier reloadAllComponents];
吗?另外,正确的委托方法是
- (NSString *)pickerView:
(UIPickerView *)pickerView
titleForRow:(NSInteger)row forComponent :(NSInteger)组件
。Did you try
[somePickerVier reloadAllComponents];
?Also, the correct delegate method is
- (NSString *)pickerView:
(UIPickerView *)pickerView
titleForRow:(NSInteger)row forComponent:(NSInteger)component
.确保设置委托和数据源?
如果没有,
您必须在 .h 文件中实现它
Make sure that you set the delegate and datasource?
If not,
You have to implement this in your .h file
你一直在使用自动释放数组
你必须保留这个
所以如果你想要你不喜欢这样,
,然后进行分配和初始化,然后
添加male,female ...
temp = [[NSArray arrayWithObjects:@“Male”,@“Female”,nil]retain];
(NSString *)pickerView:addData titleForRow:(NSInteger)row
forComponent:(NSInteger)组件 {
return [temp objectAtIndex:row];
}
u have been using autorelease array
so u have to retain this if u want
u dont like this
then do alloc and init then
add male,female...
temp = [[NSArray arrayWithObjects:@"Male", @"Female", nil]retain];
(NSString *)pickerView:addData titleForRow:(NSInteger)row
forComponent:(NSInteger)component {
return [temp objectAtIndex:row];
}