Iphone 如何使我的UIPickerView显示数组的所有元素
我有一个UIPickerView和一个数组,尽管我似乎无法将数组中的所有日期输入UIPicker 我知道语法应该是这样的:Iphone 如何使我的UIPickerView显示数组的所有元素,iphone,ios,objective-c,nsmutablearray,uipickerview,Iphone,Ios,Objective C,Nsmutablearray,Uipickerview,我有一个UIPickerView和一个数组,尽管我似乎无法将数组中的所有日期输入UIPicker 我知道语法应该是这样的: - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { return [treatments objectAtIndex:row]; } - (NSString *)pickerView:(UI
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [treatments objectAtIndex:row];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return[[treatments objectAtIndex:row]valueForKey:@"YourKey"];
}
其中,treatments是数组名,但当我使用它时,会出现以下错误:
-[Treatment isEqualToString:]: unrecognized
我已经搜索了整个项目,但找不到短语:isEqualToString
处理.h文件:
#import <Foundation/Foundation.h>
@interface Treatment : NSObject {
NSString *treatmentid;
NSString *treatmentName;
NSString *treatmentPrice;
}
@property (nonatomic, strong) NSString *treatmentid;
@property (nonatomic, strong) NSString *treatmentName;
@property (nonatomic, strong) NSString *treatmentPrice;
@end
如果你需要更多的代码,就说
提前感谢如果您的数组包含Dictionars或NSMutableDictionars,则必须使用其键指定数组的值,如下图所示。请尝试这样编写方法:
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [treatments objectAtIndex:row];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return[[treatments objectAtIndex:row]valueForKey:@"YourKey"];
}
以下是Picker view示例代码的基本实现:-
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thepickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)thepickerView numberOfRowsInComponent:(NSInteger)component
{
return [treatments count];
}
自定义UIpickerview的显示标签,如下图所示:-
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 37)];
if (component == 0) {
label.font=[UIFont boldSystemFontOfSize:22];
label.textAlignment = UITextAlignmentCenter;
label.backgroundColor = [UIColor clearColor];
label.text = [NSString stringWithFormat:@"%d", row];
label.font=[UIFont boldSystemFontOfSize:22];
NSLog(@"%@",[yourpickerview selectedRowInComponent:component]);
}
return label;
}
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
NSLog(@"%@",[treatments objectAtIndex:row]);
}
删除你的应用程序。从模拟器,清理你的项目,然后重新运行。我该怎么做???我对这东西很陌生,所以去你的模拟器,按下应用程序的图标,删除你的应用程序。然后转到xcode项目和“产品”手册并选择“清洁”。。然后运行你的应用程序@iPatel还是一样的问题我想给你一个解决方案,你介意我问你另一个突然出现的问题吗