![](/img/trans.png)
[英]calling a parent UIViewController method from a child UIViewController
[英]Is there a way To call a Child UIViewController method from Parent UIViewController?
我是Objective-c的新手,我的問題是在(xcode)中,Parent UIViewController正在監視Ibeacon,並且當用戶轉到Child UIViewController時,監視仍在運行,我需要從Parent調用Child VC方法。 就像更改“實際最近的信標”一樣,我想提醒用戶“嘿!您已移動!等”。 有適當的方法嗎? (對不起,英語不好,如果我不太明確的話)
有幾種方法可以做到這一點。
您的ParentViewController可以保留指向ChildViewController的指針並調用其函數,該函數將在ChildViewController中編寫,類似於showUserAlert。 一旦觸發,您可以顯示警報。
有ParentViewController火災的NSNotification
從NSNotificationCenter
。 孩子應該聽並采取相應的行動。
我顯然會去第一個。
如果您的父母只有一個孩子:
MyChildController* child = self.childViewControllers[0];
[child yourMethod];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.