【问题标题】:simple question - sending NSString to another class简单的问题 - 将 NSString 发送到另一个类
【发布时间】:2011-11-12 14:04:09
【问题描述】:
    //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 出来

【问题讨论】:

  • 尝试提问,而不是代码转储。

标签: iphone class nsstring send


【解决方案1】:
-(IBAction)sendString1:(id)sender {

    string1 = @"firststring";

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-09
    • 1970-01-01
    • 2019-12-15
    相关资源
    最近更新 更多