2012-04-05 52 views
0

我正試圖在選項卡欄應用程序中開發一個RSS閱讀器向下鑽取故事板。我設法用解析的XML填充我的RootTableViewController。我現在有一個問題,弄清楚如何讓我的RootTableViewController中的每一行指向並將所選單元格的數據傳遞給另一個DetailTableViewController。UITableView詳細說明使用故事板的UITableView向下鑽取

這是我的代碼部分來解析XML和填充RootTableViewController:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [stories count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"AdvCurrentCelly"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 
    int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1]; 
    NSString *description = [[stories objectAtIndex: storyIndex] objectForKey: @"description"]; 
    NSString *title = [[stories objectAtIndex: storyIndex] objectForKey: @"title"]; 

    //This populates the prototype cell 'AdvCurrentCelly' 
    cell.textLabel.text = title; 
    //cell.textLabel.text = date; 
    cell.detailTextLabel.text = description 

    return cell; 

} 

在故事板,從RootTableViewContoller細胞的DetailTableViewController的SEGUE的名字是ShowADVDetail

幫助不大讚賞

Jan

回答

1

您可以傳遞任何類型的數據,但我會告訴你如何傳遞你的標題字符串。讓我們稱之爲myString。首先,你需要在你的DetailTableViewController.h添加屬性來存儲您的字符串:

@property (strong, nonatomic) NSString *myString

在你RootTableViewController你需要告訴SEGUE做什麼。以此代碼爲例:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    // Refer to the correct segue 
    if ([[segue identifier] isEqualToString:@"ShowADVDetail"]) { 

     // Reference to destination view controller 
     DetailTableViewController *vc = [segue destinationViewController]; 

     // get the selected index 
     NSInteger selectedIndex = [[self.teamTable indexPathForSelectedRow] row]; 

     // Pass the title (from your array) to myString in DetailTableViewController: 
     vc.myString = [NSString stringWithFormat:@"%@", [[stories objectAtIndex:selectedIndex] objectForKey: @"Title"]]; 
    } 
}