2010-06-10 48 views
0

我有麻煩負載找出如何做到這一點,創建向下鑽取詳細的UITableView

我想在UITableDetailView(向下鑽取樣式)與在每個項目顯示此不同的細胞。我讀過的所有東西都顯示瞭如何在細節上加載單個圖像,而不是顯示爲UITableView。字典是否必須有「孩子」才能正確加載?這裏是第一個視圖從JSON rowsArray創建* dict的代碼。

我想我要找的是放入FollowingDetailViewController.m以查看* dict內容的其餘部分,因此當選擇一行時,它會加載* dict的其餘部分。

我有rowsArray回來如下:

'{loginName = Johnson;

memberid = 39;

name = Kris;

年齡=;},等等,等等...

感謝,

//設置表&細胞

- (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)viewDidAppear:(BOOL)animated { 
     [super viewDidAppear:animated]; 



- (void)viewDidLoad { 
    [super viewDidLoad]; 

//GET JSON FROM WEBSERVICES: 
    NSURL *url = [NSURL URLWithString:@"http://10.0.1.8/~imac/iphone/jsontest.php"]; 
    NSString *jsonreturn = [[NSString alloc] initWithContentsOfURL:url]; 

    NSData *jsonData = [jsonreturn dataUsingEncoding:NSUTF32BigEndianStringEncoding]; 
NSError *error = nil; 

    NSDictionary * dict = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error]; 
    if (dict) 
    { 
     rowsArray = [dict objectForKey:@"member"]; 
     [rowsArray retain]; 
    } 


[jsonreturn release]; 

} 

//GO TO DETAIL VIEW: 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    FollowingDetailViewController *aFollowDetail = [[FollowingDetailViewController alloc] initWithNibName:@"FollowingDetailView" bundle:nil]; 
    [self.navigationController pushViewController:aFollowDetail animated:YES]; 
} 

回答

0

不要使用阻塞調用來檢索JSON 。如果你的網絡速度很慢,你的應用程序將掛起您應該使用異步方法來檢索數據。

研究將JSON內容加載到模型對象中。然後使用一組模型來爲你的tableview提供動力。然後,DidSelectRowAtIndexPath可以通過自定義初始化程序或通過在alloc/init之後設置屬性將模型對象的實例傳遞到您的詳細視圖。你的問題很難解析,所以我不確定我是否正在處理你的問題。查看開發人員網站上的表格視圖UI層次結構的大量示例。

+0

謝謝,我傾向於你的方法,在我得到表格加載後,我將把數組保存到一個.plist中,以便在啓動時持久化並重新加載。檢查數據是否可用。我可以保存並使用JSON對象模型,對嗎? – 2010-06-11 12:57:57

+0

我只是將模型對象作爲爲您的目的而量身定製的通用nsObject。你可以堅持plist,sqllite,核心數據等。 – Nick 2010-06-11 16:02:24