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

In fact, I'm testing an example application on the iPhone ... where in the user interface, if I press the hello button, the message should be displayed in the text box ... so that when the button is pressed it should call a method present in another class , that is, from class 2 and displaying the message in the user interface so help me .... the following code is below I have two classes: class1 and class2 ... in class1 I'm calling

Class1.h

@interface class1 : UIViewController {

      IBOutlet UILabel *statusText;    


}

@property (nonatomic,retain)UILabel *statusText;

- (void)buttonpressed:(id)sender;

@end

class1.m

@implemenation class1

-(IBAction)sayhello:(id)sender

{
class1ViewController *class = [[class1ViewController alloc]init];

    [class hello];
}

class2.h

@interface class2 : UIViewController {

    UILabel *statusText;
}

@property(nonatomic,retain)UILabel *statusText;


-(void)sayhello:(id)sender;


@end

class2.m

@implementation class2

-(void)sayhello:(id)sender;
{

    NSString *newtext = [[NSString alloc] initWithFormat:@"hello"];

    statusText.text = newtext;

    [newtext release];
 }   

, , , "HELLO", .... . IBAction ... , .

...

+3
4

,

class1ViewController *class = [[class1ViewController alloc]init];

, : -

-(IBAction)sayhello:(id)sender

{
class2 *class = [[class2 alloc]init];
   NSString *string= [class sayhello];
    [class release];
label.text=string;
}

2 class1

2   : -

-(NSString)sayhello
{
    return @"hello";

 }  
+2

[class hello] [class sayhello:nil].

: , . Class1 Class2. , buttonpressed: a sender, . , :(id)sender. text statusText, . : statusText.text = @"hello";

+2

,

class2 * _class2Object = [[class2 alloc]init];
[_class2Object sayHello];

2 1, , 2 1, class2.h class1 .

+1

, ( , , ), , , ( class2).

I suggest you display some line made by class2 in a view of class 1:

therefore in class1:

-(IBAction)sayHello
{
class2* c2 = [[class2 alloc] init];
statusText.text = [c2 sayhello];
[c2 release];
}

in class2:

-(NSString*)sayhello
{
return @"a string";
}
0
source

All Articles