2

I can not add a delegate to a subview

 2 years ago
source link: https://www.codesd.com/item/i-can-not-add-a-delegate-to-a-subview.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

I can not add a delegate to a subview

advertisements

I am having some main viewController , that i want to add a subview to it, as a child, which is also a viewController .

My approach is that when you finish editing that subview, he will tell the main view to do something with a delegate.

  1. does this approach to create many subviews as viewcontrollers that being added to the main view, and notify him with delegate when something happens , is a good approach ?

  2. why can't i add a delegate listener to my subview ? i created the protocol in my subview, and the main view is adding a subview and needs to subscribe to its delegate , so :

UIViewController *search = [[SearchView alloc]init]; //my subview that post delegate
    //[search delete:self]; //can't add delegate here,
    [self addChildViewController:search];
    // search.view.frame = CGRectMake(0, 0, 0, 550);
     [self.view addSubview:search.view];
    [search didMoveToParentViewController:self];


There is no delegate property in UIViewController but you call

[search delete:self];

On this object, not on SearchView object. If you added delegate property on SearchView you need to change the declaration to:

SearchView *search = [[SearchView alloc]init];

The other thing is if you added delegate in SearchView.h file like:

@property(assign) YOURDEL delegate; you should call:

[search setDelete:self];

instead of:

[search delete:self];


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK