Setting the delegate when destination is not UIViewController

时间:2016-02-12 20:16:34

标签: ios uistoryboardsegue uicontainerview

I have been reading around stackover flow as well as internet. This might be my limited knowledge that I am not able to find the way to solve this problem. Following is my storyboard setting. enter image description here

For sake of understanding lets call them firstVC secondPageVC and thirdTableVC I am basically showing the pageViewController in container view where page view controller inturn have tableView. my first scene in story board have method which is fetching the data over the internet. I need to pass this data down such a way that my tableview is populated.

With my research and trial I have found. PrepareForSegue in FirstVC is being call right away as containerView need to fill in with content, which is inturn is pageViewController. As soon as secondPageVC Load it need to find its startup view controller. So soon as secondPageVC loaded it tries to load thirdTableVC.

I have wrote a protocol in firstVC, so that I can pass on the data when its get updated. I am so stumped, which View controller should be delegate or conform to this protocol. I am trying to make secondPageVC to conform this protocol as its next VC where controller is being pass and first logical choice. but how to set delegate if I am not using the prepareForSegue. I am unable to use prepareForSegue as destinationViewController must be a UIViewController.

Would love to have some pointer on this problem. please comment if more clarification is needed on the problem.

Update: Thanks to folks who replied. Their thought spawn a doubt in me. What I am trying to do. Is that a good solution. As one fellow suggestion to have notifications. Which defiantly can be another approach.

1 个答案:

答案 0 :(得分:0)

When you're thinking about delegation, you need to know which objects need to be updated. Whatever needs to be updated when something changes should be the delegate. Whatever is going to do the updating should have the delegate property.

In this specific case, since your <form> <ul class="form_style"> <li><label>Full Name</label><input type="text" id="fname" name="fname" class="field-divide" value="<?php echo $_SESSION["firstname"];?>" />&nbsp;<input type="text" id="lname" name="lname" class="field-divide" value ="<?php echo $_SESSION["lastname"];?>"placeholder="Last name"/> </li> <li> <label>Email</label> <input type="email" id="email" name="email" class="long" value="<?php echo $_SESSION["email"];?>"/> </li> <li> <label>Password</label> <input type="password" id="password" name="password" class="long" value="<?php echo $_SESSION["password"];?>"/> </li> <li> <input type="submit" name="update" id="update" value="Update"/> </li> </ul> </form> is going to do the updating, it should be the object that has a delegate property.

You should be able to use firstVC without any issues. Yes, prepareForSegue will be of type destinationViewController, but you know that it will be your view controller's type as long as the segue is the segue you're thinking of. You can simply cast the UIViewController to the correct type, and then set the delegate property.