0

I have created a popup and in that there is a list of content are displaying in a table view. Now when I click into any row of the tableview, it should call a method, which is available in the parent view not in the popup view. If I use any button in that popup then after selecting a row if I click into that button then it works. The button action is mention in parent view in this way.

[controller.gotoButton addTarget:self action:@selector(clickMe:) forControlEvents:UIControlEventTouchUpInside]; 

So how to call a method when clicking into a table rows?

4
  • Would you be a little more specific? So, when you click on the button from the popup, it should take some effect in the parent view? Commented Sep 4, 2012 at 10:24
  • See Class A is a view and in that a button is there if I click that button then a popup will display(let say B). in popup a list of contents is there and if I click any one it should call a function from A. Is there any other way we will implement this Commented Sep 4, 2012 at 10:39
  • Yes, you can try with protocols. On the "answers" I posted about protocols. Please, let me know if you have questions about this. Commented Sep 4, 2012 at 10:40
  • is it a UIPopoverController you are talking? Commented Sep 4, 2012 at 10:58

2 Answers 2

1

Here you can find a pretty good description of delegates.

What you would like to do, can be solved with a protocol/delegate. You should create the protocol in the Popup view's header file, and the implementation in the *.m class. Your parent view should implement the protocol, and don't forget the connection line, the myPopupObject.delegate = self; + the implementation of the protocol's method.

I suggest to use the

if ([delegate respondsToSelector:@selector(myMethod:)]) { //call the selector } 

verification in the Popup view class, because if the protocol's method is optional, and you hadn't implemented it in the parent class, your app will crash (you won't receive any error/warning message from the compiler, because it was an optional method).

Sign up to request clarification or add additional context in comments.

2 Comments

Hi,I have created a project name "popup" and here is the code
I cannot find the project. Where should I look for it exactly?
0

in rowDidSelect,

create a object for the parentview eg:

 parentClass *pc=[parentClass alloc]init]; [pc method:]; 

1 Comment

Yes I understand what u want to say. See Class A is a view and in that a button is there if I click that button then a popup will display(let say B). in popup a list of contents is there and if I click any one it should call a function from A. Is there any other way we will implement this.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.