2012-02-15 83 views
0

我有從一個從網址抓取的數組填充的表視圖。我使用數組的字符串對象中的幾個字符設置每行的標題,並在單擊單元格時推送新的視圖。在這個新的觀點,我有一個UILabel。在這一點上我想是,設置此拉布勒與指數的滿弦的冠軍。如何在新視圖中顯示數組索引的詳細信息?

這裏是我的代碼:

NSDictionary *object=[[NSUserDefaults standardUserDefaults]objectForKey:@"savedMessage"]; 
    NSArray *array= [object valueForKey:@"message"]; 


    cell.textLabel.text= [array objectAtIndex:indexPath.row]; 

,並通過下面的代碼我推新觀點:

messageDetail *detailViewController = [[messageDetail alloc] initWithNibName:@"messageDetail" bundle:nil]; 
    [self.navigationController pushViewController:detailViewController animated:YES]; 
    [email protected]"Message Detail"; 

    [detailViewController release]; 

我想的是,如何顯示在自己的索引數組的任何結果(詳細)什麼? (例如,當我點擊了5行,我想我的detailViewController的標籤被設置爲陣列的5對象)

回答

2

您創建一個messageDetail.m函數調用,像這樣:

- (void)updateLabelWith:(NSString *)labelString{ 
    label.text = labelString;} 

然後你在tableViewController調用它在didSelectRowAtIndexPath方法

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
    NSString *labelString = [data objectAtIndex:indexPath.row]; // data is an NSArray of Strings 
    [detailViewController updateLabelWith:labelString]; 
    [self.navigationController pushViewController:detailViewController animated:YES];} 
+0

感謝的人,我已經解決以不同的方式, 我救indexPath.row NSUserDefaults的到,再次檢索它在其他類作爲一個數組.. – 2012-02-15 13:23:21