1

I have a UIViewController named MainViewController. I have an another class named ViewMaker. In the ViewMaker class I have a function as follows.

 -(UIView *)GetContentView
{
UIView *return_view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];

UIButton *done_button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
done_button.frame = CGRectMake(300, 300, 100, 50);
[done_button setTitle:@"Done" forState:UIControlStateNormal];
[return_view addSubview:done_button];
return return_view;
}

In the above function actually I will add more views like textviews, labels etc.

In the MainViewController class I am calling the above method as follows.

 -(void)CreateViews
 {   
 UIView *content_view = [[[ViewMaker alloc] init] GetContentView];
 [self.view addSubview:content_view];
 }

Now I have added a view with done button(and other components like textviews, labels etc) from the MainViewController class. My problem is about adding a target function for the done button. When I click the done button I want to perform some actions(like add some views) in the MainViewController according to the datas in the view that was returned from the ViewMaker class. How can I do this? Thanks in advance.

3 Answers 3

1

I assume your ViewMaker class is same as PopupContentMaker,

add this to your done button:

[done_button addTarget:self action:@selector(doSomething) forControlEvents:UIControlEventTouchUpInside];

in PopupContenMaker:

- (void)doSomething{
if ([self.delegate respondsToSelector:@selector(handleDoneButtonTap)]) {
    [self.delegate performSelector:@selector(handleDoneButtonTap) withObject:self];
}

}

declare a delegate property in your PopupContentMaker, and make MainViewController the delegate,

-(void)GetContentView
{   
PopContentMaker *pcm = [[PopupContentMaker alloc] init];

pcm.delegate = self;

[self.view addSubview:[pcm GetContentView]];

}

-(void)handleDoneButtonTap{
//Do action after done button
}
Sign up to request clarification or add additional context in comments.

Comments

0

You can try:

[done_button addTarget: self
      action: @selector(buttonClickedMethod)
forControlEvents: UIControlEventTouchUpInside];

In this way you can call a custom method when button is pressed.

Comments

0

You can pass the target and action as parameters to the getContentView method or you can use the delegate pattern.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.