Ios UIPickerView数据问题

Ios UIPickerView数据问题,ios,objective-c,uipickerview,Ios,Objective C,Uipickerview,全部, 我有一个外部类文件,如: #import <Foundation/Foundation.h> @interface GlobalVars : NSObject { NSArray *alllocationsID; NSArray *alllocationsCity; } @property(nonatomic, copy) NSArray *alllocationsID; @property(nonatomic, copy) NSArray *alll

全部,

我有一个外部类文件,如:

#import <Foundation/Foundation.h>

@interface GlobalVars : NSObject {
    NSArray *alllocationsID;
    NSArray *alllocationsCity;
}


@property(nonatomic, copy) NSArray *alllocationsID;
@property(nonatomic, copy)  NSArray *alllocationsCity;


@end
这将带来正确的.count数量,即14,因此它将从全局类文件中获取数据

但是在我的numberofRowsinCompent中,global.allocationsID.count带来0,难怪picker视图不显示

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {


    GlobalVars *Global = [[GlobalVars alloc] init];
    NSLog(@"%lu",(unsigned long)Global.alllocationsID.count);

    NSInteger numRows = Global.alllocationsID.count;

    return numRows;
有什么想法吗?

在numberofRowsinComponent中,您不应该分配GlobalVars

所以在h

然后在

然后在NumberOfRowUncomponent中


你有没有检查你的拼写分配ID与AllLocationSid不同我明白你的意思但是Global=[[GlobalVars alloc]init]需要分配到哪里,在视图did load或从数据库捕获数据的方法(即上面的函数-valueforkey等)中,viewdidload是更好的方法。好的,因此我添加了Global=[[GlobalVars alloc]init];对于viewdidload,在上面的方法中,NSLogs获取null,numberofrowsincomponent仍然为null。但是如果我将Global=[[GlobalVats alloc]init]添加到数据库检索函数中,那么nslog的计数是正确的,但是numberofrowsincomponent仍然为null。。帮助:这是我的。h@interfaceViewController:UIViewController{CLLocationManager*locationManager;GlobalVars*Global;}那么GlobalVars.m文件呢?
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {


    GlobalVars *Global = [[GlobalVars alloc] init];
    NSLog(@"%lu",(unsigned long)Global.alllocationsID.count);

    NSInteger numRows = Global.alllocationsID.count;

    return numRows;
GlobalVars *Global;
Global = [[GlobalVars alloc] init];
Global.alllocationsID = [[responseObject valueForKey:@"data"] valueForKey:@"ID"];
Global.alllocationsCity = [[responseObject valueForKey:@"data"] valueForKey:@"name"];
NSLog(@"%@", Global.alllocationsCity);
NSLog(@"%@",Global.alllocationsID);
NSLog(@"%lu",(unsigned long)Global.alllocationsID.count);
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {

    NSLog(@"%lu",(unsigned long)Global.alllocationsID.count);

    NSInteger numRows = Global.alllocationsID.count;

    return numRows;
 }