2011-09-07 63 views
-2
//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 

我知道這是一個簡單而容易的任務,但我很難用google搜索它,因爲它太簡單了。簡單的問題 - 發送NSString到另一個類

這也是我的項目的鏈接。

謝謝。

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

編輯:問題是在標題居然但如何發送字符串1的值,以STRING2導致目前我的NSLog的字符串2只空出來

+0

那麼,有什麼問題? –

+0

而不是代碼轉儲,請嘗試提問。 – PengOne

回答

1
-(IBAction)sendString1:(id)sender { 

    string1 = @"firststring"; 

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