簡體   English   中英

如何將單元格中的第三個值傳遞給另一個表視圖控制器

[英]How to pass a third value in a cell to another table view controller

我有一個帶有textLabeldetailTextLabelUITableViewController ,問題是我想傳遞一個具有URL “隱藏”第三個值,因此當我將行觸摸到下一個UITableViewController ,可以使用委托didSelectRowAtIndexPath來獲取URL,但是我該怎么做?

您可以將字典發送到下一個TableView。 將SecondTableView控制器.h文件導入到FirstTableView控制器中,然后引用目標字典。 您還需要實現prepareForSegue並在didSelectRowAtIndexPath中對其進行調用。 像這樣:

在didSelectRowAtIndexPath中:(如果正在使用,請確保在Storyboard中設置segue標識符)。

[self performSegueWithIdentifier:@"toSecondTableViewController" sender:nil];

在SecondTableViewController.h中創建您的字典

@property (nonatomic, retain)NSMutableDictionary *selectedDictionary;

確保在SecondTableViewController.m文件中進行合成。

然后在您的FirstTableViewController中

#import SecondTableViewController.h 
//prepareForSegue
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"toSecondTableViewController"])
    {
        //create the dictionary to store the information from the array
        NSDictionary *dictionaryToPass;
//MainTable is your TableView in your TableViewController
        NSIndexPath *indexpath = [self.MainTable indexPathForSelectedRow];
        NSLog(@"IndexPath is: %@",indexpath);
        //load correct information based on indexpath selected

            dictionaryToPass = [array objectAtIndex:indexpath.row];

        //create the view for the segue
        SecondTableViewController *secondTable = segue.destinationViewController;

//pass the dictionary
        seriesTable.selectedDictionary = dictionaryToPass;
    }
}

然后,您可以在SecondTableViewController中的selectedDictionary中引用鍵並獲取該URL。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM