开发者

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 an开发者_开发问答y nib file in my class A. plz someone ans my question. Advanced thanks for ur reply.


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"...?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜