簡體   English   中英

將變量傳遞給Objective-C中嵌入在導航控制器中的View Controller

[英]Pass variable to View Controller Embedded in Navigation Controller in Objective-C

我已經在導航控制器中嵌入了目標ViewController,現在無法將其傳遞給變量。

我的代碼是:

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
//THis is the navigation controller 
    UIViewController *destVC = [storyboard instantiateViewControllerWithIdentifier:@"myNav"];
//This is the view controller embedded in the nav
    IDNowVC* myVC = [storyboard instantiateViewControllerWithIdentifier:@"myVC"];
   myVC.sender = @1;//for contacts

   [self presentViewController:destVC animated:YES completion:nil];

VC啟動后,sender屬性為nil。 它沒有得到值@ 1。

我想念什么?

感謝您的任何建議。

在您的代碼中,您有一條注釋,內容為:

//這是嵌入到導航中的視圖控制器

但是,該注釋下方的視圖控制器不是導航控制器中嵌入的視圖控制器。 這是一個全新的控制器,它在該行創建並在函數末尾廢棄。

您需要這樣的東西:

UINavigationController *destVC = (UINavigationController *)[storyboard instantiateViewControllerWithIdentifier:@"myNav"];
IDNowVC* myVC = destVC.childViewControllers[0];
myVC.sender = @1; 

以上內容可能存在語法問題...

暫無
暫無

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

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