0
我有一個NSURL請求,它返回一個「名稱」和「電話」,「等」數組......「名稱」鍵在主服務器上顯示正常表,但我無法弄清楚當我選擇行時如何讓數組的其餘部分顯示在細節表上。 (我有DetailerTableViewController工作接受視圖)。任何幫助,將不勝感激。將此JSON數組中的附加字符串轉換爲UITableView詳細信息
感謝,
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [rowsArray count];
NSLog(@"row count: %@",[rowsArray count]);
}
- (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];
}
NSDictionary *dict = [rowsArray objectAtIndex: indexPath.row];
cell.textLabel.text = [dict objectForKey:@"name"];
cell.detailTextLabel.text = [dict objectForKey:@"loginName"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.0/255.0 green:207.0/255.0 blue:255.0/255.0 alpha:1.0];
self.title = NSLocalizedString(@"Master", @"Master");
NSURL *url = [NSURL URLWithString:@"http://10.0.1.8/~imac/iphone/jsontest.php"];
NSString *jsonreturn = [[NSString alloc] initWithContentsOfURL:url];
NSLog(jsonreturn); // Look at the console and you can see what the results are
NSData *jsonData = [jsonreturn dataUsingEncoding:NSUTF32BigEndianStringEncoding];
NSError *error = nil;
// In "real" code you should surround this with try and catch
NSDictionary * dict = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error];
if (dict)
{
rowsArray = [dict objectForKey:@"member"];
[rowsArray retain];
}
NSLog(@"Array: %@",rowsArray);
NSLog(@"count is: %i", [self.rowsArray count]);
[jsonreturn release];
}
謝謝 - 我有,它推動,但結果頁面只是「名稱」cell.textLabel.text = [字典objectForKey:@「名稱」];我想要顯示數組中的所有其他名稱。 – 2010-06-05 11:46:30
你用這種方法推什麼?如果您推送另一個表視圖控制器,則需要將每行設置爲單獨的一行數據。或者,您可以在您的自定義UIViewController子類中使用您填寫的UILabels創建自己的視圖。 – lucius 2010-06-06 08:57:28
我沒有推另一個視圖控制器,我遇到了一個確切的問題,我必須有一個單獨的視圖控制器,因爲該視圖除了詳細信息表之外還有一些項目,我想我的問題需要是:如何設置從上表中爲數組中的每個項目分開單元格? – 2010-06-07 20:32:02