russell
russell

Reputation: 3766

How to call function of one class from another class programatically

I called function of one view controller class from other view controller in nib file using first responder before.But now I want to do it programatically.

Suppose,I have a 2 controller class named A and B.where B is root controller.I have a button(added programatically)named (Btn) in my A controller class.now I want to call function( FuncB) of Class B when I pressed Btn of Class A.how can I do this??

I dont have any nib file in my class A. plz someone ans my question. Advanced thanks for ur reply.

Upvotes: 1

Views: 910

Answers (2)

Henrik P. Hessel
Henrik P. Hessel

Reputation: 36617

Alloc and init an instance of this class and call your method. Class "functions" are called methods.

BController *myBController = [[BController alloc] init]; // alloc and init Controller B
[myBController MethodB]; // Call your class method
[myBController release]; // release your instance object

Any questions? Just comment.

Upvotes: 1

Steve Harrison
Steve Harrison

Reputation: 125480

I'm not sure whether I've interpreted your question correctly, but if b is an object instance of the B class, and methodB is a method of the B class, you can call methodB via:

[b methodB];

I am assuming by "function", you actually mean "method"...?

Upvotes: 1

Related Questions