简单的问题 - 将 NSString 发送到另一个类

发布于 2024-12-03 08:53:02 字数 1502 浏览 1 评论 0原文

    //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
#import <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

我知道这是一项简单易行的任务,但我很难在谷歌上搜索它,因为它太简单了。

这也是我的项目的链接。

谢谢。

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

编辑:问题实际上是在标题上,但是我如何将 string1 的值发送到 string2 因为当前当我 nslog 时 string2 仅出现 null

    //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
#import <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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

脸赞 2024-12-10 08:53:02
-(IBAction)sendString1:(id)sender {

    string1 = @"firststring";

    MyClass *mc = [[MyClass alloc]init];
    mc.string2 = string1;
    [self presentModalViewController:mc animated:YES];
}
-(IBAction)sendString1:(id)sender {

    string1 = @"firststring";

    MyClass *mc = [[MyClass alloc]init];
    mc.string2 = string1;
    [self presentModalViewController:mc animated:YES];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文