How to call a method from another class method which consists of IBAction method?

Are you aware of writing this class1ViewController *class = class1ViewController allocinit; I think it should be:- -(IBAction)sayhello:(id)sender { class2 *class = class2 allocinit; NSString *string= class sayhello; class release; label. Text=string; } don't forget to import class2 in class1 in class2 simply write:- -(NSString)sayhello { return @"hello"; }.

Abhilash I am curious to know does the answer help you. – Gypsa Jun 1 at 12:57 yup it works thanks a lot....... – Abhilash Jun 2 at 4:24.

Instead of class hello, use class sayhello:nil. A few notes: the names of classes should begin with a capital letter, e.g. Class1 and Class2. Also, buttonpressed: passes a sender, you are however not using it.

It also works when you remove the :(id)sender. And when you set the text of statusText, you create a new string first. This does the same: statusText.

Text = @"hello.

Hope this helps class2 * _class2Object = class2 allocinit; _class2Object say and don't forget to import class2 in class1 else app may crash, since you want to call the method of class2 in class1 so import the class2. H header in class1 and add the above code.

Theoretically, since you are calling a object method(I suppose you know what is the difference between a object method and a class method), so you should alloc and initiate a object of the class which contains the method you want to call(here class2). I suggest that you display some string made by class2 in class1's view: so in class1: -(IBAction)say { class2* c2 = class2 alloc init; statusText. Text = c2 sayhello; c2 release; } in class2: -(NSString*)sayhello { return @"a string"; }.

This also works thanks a lot.... – Abhilash Jun 2 at 4:27 tel me difference between object method and class method...? – Abhilash Jun 2 at 4:34 @Abhilash to call a object method, you must have a instance of a class, like c2 sayhello; above. To call a class method, you don't have to have a instance of a class, if class2 has a class method named sing you can call like this: class2 sing – user465191 Jun 2 at 7:19 @Abhilash check this question's answer:stackoverflow. Com/questions/1053592/… – user465191 Jun 2 at 7:19 thank u........ – Abhilash 1 Jun3 at 4:28.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions