0
編輯UIPickerview給questionmarks回來,而不是數據
我有一個UIPickerView,我想就從我的NSMutualArray數據填滿它。我測試過,如果有什麼東西在我的數組與NSLog和我得到的數據回來。但它不會填滿我的pickerviewer
我有這個方法我pickerviewer。
- (NSString *)pickView:(UIPickerView *)pickview titleForRow:(NSInteger)row forComponent:(NSInteger)component{
return [dataArray objectAtIndex:row];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 1;// assuming a single spinning wheel of strings (not split into left/right for example)
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
return [json count]; // the number of strings that your parser finds and adds to the array
}
爲了從我的JSON中獲取我的數據,我使用了這兩種方法。我在我的viewdidload中調用start函數。
-(void) getData:(NSData *) data{
NSError *error;
json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
}
-(void) start {
NSURL *url = [NSURL URLWithString:kGETUrl];
NSData *data = [NSData dataWithContentsOfURL:url];
[self getData:data];
}
我也有一個按鈕,用於隱藏和顯示我的UIPickerviewer。
-(IBAction)setPicker:(id)sender{
if (pickview.hidden == TRUE) {
[pickview setHidden:NO];
[pickview setDelegate:self];
[pickview setDataSource:self];
[pickview reloadAllComponents];
}else {
[pickview setHidden:YES];
[pickview setDelegate:self];
[pickview setDataSource:self];
[pickview reloadAllComponents];
}
}
我用這個方法來填充我的數組。
-(void) fillArray{
dataArray = [[NSMutableArray alloc] init];
for (int i=0; i<[json count]; i++) {
NSDictionary *info = [json objectAtIndex:i];
[dataArray addObject:[info objectForKey:@"Use_naam"]];
}
NSLog(@"%@\n",dataArray);
}
我這樣稱呼它在我viewDidLoad中。
- (void)viewDidLoad
{
[super viewDidLoad];
[self start];
[self fillArray];
// Do any additional setup after loading the view, typically from a nib.
}
有人知道我在做什麼錯嗎?
問題是有我的朋友。代碼使用了什麼參考?你在編碼自己嗎?什麼是json?你是否也收到信息的任何數據? – Sarah
但還沒有? – Sarah
沒有它填補了questionmarks的pickerviewer – steaphann