我是 Objective-C 编码的新手。但是,如果您看一下我的输出下面的图像,我的问题就很简单了。基本上我希望所有内容都正确对齐,以便行中的所有数据看起来就像它们在自己的列中一样。基本上每一行都应该与它上面的行对齐。我的程序从网络上的 JSON 文件中引入每个字段 - 另请参阅代码以了解我是如何做到的。
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSDictionary *allDataDictionary = [NSJSONSerialization JSONObjectWithData:webData options:0 error:nil];
for (NSDictionary *diction in allDataDictionary) {
NSString *currDate = [diction objectForKey:@"Current Date"];
NSString *timePeriod = [diction objectForKey:@"Time Period"];
NSString *transCount = [diction objectForKey:@"Transaction Processed"];
NSString *approved = [diction objectForKey:@"Approved"];
NSString *posApproved = [diction objectForKey:@"Standing App"];
NSString *approvalRate = [diction objectForKey:@"Approval Rate"];
NSString *respTime = [diction objectForKey:@"Resp Time"];
[array addObject:[NSString stringWithFormat:@"%@ %@ %@ %@ %@ %@", timePeriod, transCount, approved, posApproved, approvalRate, respTime]];
} [[self myTableView] reloadData];
我的表视图:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(!cell)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// NSString *currDate = [[array objectAtIndex:indexPath.row] objectForKey:@"Current Date"]; //added
// NSString *someOtherKey = [[array objectAtIndex:indexPath.row] objectForKey:@"Some other key"]; //added
cell.textLabel.text = [array objectAtIndex:indexPath.row];
// cell.textLabel.text = [NSString stringWithFormat:@"%@ %@", currDate, someOtherKey]; //added
return cell;
}