简单的问题 - 将 NSString 发送到另一个类
//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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)