爲了設置UITableView單元格的字體,textLabel和顏色,iOS 7中已經棄用了很多方法。我也很難用這些值填充視圖。這裏是我的代碼片段:在iOS 7中使用NSArray填充UITableView
- (void)fetchedData:(NSData *)responseData {
//parse out the json data
NSError* error;
NSDictionary* json = [NSJSONSerialization
JSONObjectWithData:responseData
options:kNilOptions
error:&error];
NSArray* jobs = [json objectForKey:@"results"];
for(NSDictionary *jobsInfo in jobs) {
JobInfo *jobby = [[JobInfo alloc] init];
jobby.city = jobsInfo[@"city"];
jobby.company = jobsInfo[@"company"];
jobby.url = jobsInfo[@"url"];
jobby.title = jobsInfo[@"jobtitle"];
jobby.snippet = jobsInfo[@"snippet"];
jobby.state = jobsInfo[@"state"];
jobby.time = jobsInfo[@"date"];
jobsArray = [jobsInfo objectForKey:@"results"];
}
}
我正在循環訪問GET請求和解析的字典數組。我現在試圖填補我的UITableView用下面的代碼:
-
(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [jobsArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSDictionary *jobsDic = [jobsArray objectAtIndex:indexPath.row];
[cell.textLabel setText:[jobsDic objectForKey:@"jobtitle"]];
return cell;
}
而且,我宣佈這是我的.h文件:
NSArray *jobsDic;
任何想法什麼我做錯了嗎?這是iOS 7的問題嗎?
你在哪裏解析JSON到viewDidLoad? –
我在tableView中選擇了一個單元格,並將它推入另一個UITableView,然後調用一個方法來解析數據。 –
你有沒有檢查數組是否已經沒有進入tableView:numberOfRowsInSection: –