我是iOS开发和Objective-C编程的新手,所以原谅我的“不高兴”。tableView不填充数组中的数据
这是事情,我有一个函数,它构建一个从JSON对象获取数据的数组。 然后我有第二个函数,负责填充我的数组中包含的数据的tableView。
问题是,即使该数组已添加到我的头文件并在主文件中实现,但该数组的内容似乎无法从我的tableView函数中访问。 该tableView保持空...
你知道这是为什么吗?
以下是函数,谢谢你的帮助!
1)数组建筑功能:
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[self.responseData appendData:data];
//Get data
NSError *myError = nil;
NSDictionary *res = [NSJSONSerialization JSONObjectWithData:self.responseData options:NSJSONReadingMutableLeaves error:&myError];
//Extract titles
NSMutableArray *myResults = [[NSMutableArray alloc] init];
NSArray *results = [res objectForKey:@"data"];
for (NSDictionary *result in results) {
NSString *title = [result objectForKey:@"colors"];
NSLog(@"colors: %@", colors);
[myResults addObject:colors];
}
self.colorNames = myResults;
}
2)的TableView灌装功能:
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
//Set cell text
NSString *colorString = [self.colorNames objectAtIndex: [indexPath row]];
NSLog(@"%@",colorString);
cell.textLabel.text = colorString;
return cell;
}
控制器是一个TableViewController还是一个带有TableView的ViewController? – 8vius 2012-08-07 20:39:12