开发者

simple question - sending NSString to another class

开发者 https://www.devze.com 2023-04-03 15:09 出处:网络
//StringStringViewController.h #import <UIKit/UIKit.h> #import \"MyClass.h\" @interface SendStringViewController : UIViewController {
    //StringStringViewController.h    
    #import <UIKit/UIKit.h>
        #import "MyClass.h"

        @interface SendStringViewController : UIViewController {
            NSString *string1;
            MyClass *secondview;
        }

        @property (nonatomic, retain) NSString *string1;
        @property (nonatomic, retain) MyClass *secondview;

        -(IBAction)sendString1:(id)sender;

        @end

//  SendStringViewController.m
#import "SendStringViewController.h"


@implementation SendStringViewController
@synthesize string1;
@synthesize secondview;

-(IBAction)sendString1:(id)sender {

    string1 = @"firststring";

    secondview.string2 = string1;

    MyClass *mc = [[MyClass alloc]init];
    [self presentModalViewController:mc animated:YES];
}


@end


//  MyClass.h
#impor开发者_JAVA百科t <UIKit/UIKit.h>

@interface MyClass : UIViewController {
    NSString *string2;
}

@property (nonatomic, retain) NSString *string2;

@end


//  MyClass.m
#import "MyClass.h"

@implementation MyClass
@synthesize string2;

- (void)viewDidLoad {

    NSLog(@"%@", string2);

    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

@end

I know it's a simple and easy task but I'm having hard time googling it, because it's way too easy.

Here's the link of my project too.

Thanks.

http://dl.dropbox.com/u/12439052/SendString.zip

Edit: the question is on the title actually but how do i send the value of string1 to string2 cause currently when i nslog the string2 only null comes out


-(IBAction)sendString1:(id)sender {

    string1 = @"firststring";

    MyClass *mc = [[MyClass alloc]init];
    mc.string2 = string1;
    [self presentModalViewController:mc animated:YES];
}
0

精彩评论

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

关注公众号