我是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;
}
很高興知道,謝謝。你有什麼建議,我可以如何協調一切? – user1832095
使用\ t分隔每個元素,如果文本的長度有些相似,它應該對齊文本,否則可以使用兩個標籤。 – Sandeep
不幸的是,這將無法正常工作,因爲每個元素可能會有不同數量的數字,因爲他們進來 – user1832095