Ios 无法访问实例变量
我有一个UTableView。我想将我的数据拆分为类别组。我有一个实例变量,它包含数据库中的所有组Ios 无法访问实例变量,ios,objective-c,uitableview,cocoa-touch,uikit,Ios,Objective C,Uitableview,Cocoa Touch,Uikit,我有一个UTableView。我想将我的数据拆分为类别组。我有一个实例变量,它包含数据库中的所有组 @interface TableViewController : UITableViewController { // Response from server NSString* serverResponse; NSMutableArray *categories; // This NSMutableArray contains all category's s
@interface TableViewController : UITableViewController {
// Response from server
NSString* serverResponse;
NSMutableArray *categories; // This NSMutableArray contains all category's server
}
@property (strong) NSString *serverResponse;
@property (strong) NSMutableArray *categories;
我用requestFinished方法填充NSMutableArray,所有方法都可以完美地工作
- (void)requestFinished:(ASIHTTPRequest *)request
{
NSString *result = request.responseString;
NSArray *jsonArray = (NSArray*)[result JSONValue];
int count = [jsonArray count];
int i;
NSDictionary *jsonDict = [[NSDictionary alloc] init];
for (i = 0; i < count; i++) {
jsonDict = [jsonArray objectAtIndex:i];
NSString *current = [jsonDict objectForKey:@"categoriy"];
[categories addObject:current];
NSLog(@"%d", [categories count]) // Shows 4 -> ok !
}
}
它显示在控制台0上
我真的不明白为什么
也许有人能帮我解决这个问题?问题可能是在调用requestFinished:之前调用了numberOfSectionsInTableView:
我想你必须重新加载tableview
请尝试将[self.tableView reloadData]或类似内容放在requestFinished:的末尾
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
NSLog(@"%d", [categories count]) // Show 0 -> bad !
return [categories count];
}