(Storyboard) Possible doing design of a custom view in one controller, and re-use it in different?

MwBMwB NLMember ✭✭
edited July 2017 in Xamarin.iOS

Good day all,

I am used to create a custom view in a class by code, and re-use this custom classed view in different controllers.

However; it would save me some time if I could do the design in a certain designViewController on a storyboard and then use this custom class elsewhere in a different viewcontroller.

When I now use UITableStyleButton.cs it gives me a blank view.

Answers

  • Max_MacFarlaneMax_MacFarlane USMember ✭✭

    @MwB

    I might be completely wrong with what you are trying to accomplish here but what I think you are trying to do is design a view and then be able to re use that.

    Here is a code snippet which gets a view from the storyboard and adds it to your current controller.

    // Get View controller from storyboard
    UIViewController viewController = Storyboard.InstantiateViewController("StoryBoardID");
    
    // Add view controller as a child of its parent.
    AddChildViewController(viewController);
    viewController.View.TranslatesAutoresizingMaskIntoConstraints = false;
    
    // Add child to parent view
    View.AddSubview(viewController.View);
    viewController.DidMoveToParentViewController(this);
    

    If this isn't what you are after could you provide some more information of what you are trying to achieve.

  • MwBMwB NLMember ✭✭

    I am trying to create a custom view with it's class and do the design in Storyboard, to save time rather doing the designing in code.

    I did not realize it would required me to 'take' that ViewController in which I designed the custom view since the custom view already has a class on its own.

    All I need is the button I created, it seems redundant to get the entire viewController as a whole to 'pick' my UIview (which, as stated already has a custom class by istelf)

  • Max_MacFarlaneMax_MacFarlane USMember ✭✭

    @MwB

    Unfortunately I am not sure how you would achieve what you require. I'm sure its possible but I just don't know how.

  • MwBMwB NLMember ✭✭

    No worries, I already appreciate the time you have taken for the answers :)

Sign In or Register to comment.