我一直对此感到困惑
我似乎永远找不到很好的解释,我理解继承,但是从我学到的知识是在主类和它们的子类之间...如果我想将NSString传递给另一个类而不是子类,该怎么办?其他
这里是一个例子:
class1.h
@interface class1 : UIViewController{
NSString *string
}
@property (nonatomic, retain) NSString *string
@end
class1.m
@implementation class1
@synthesize string;
-(void)viewDidLoad{
string = @"IM A STRING AHHH";
}
现在让我说我想将该字符串传递给另一个类
class2.h
#import "class1.h"
@interface class2 : UIViewController{
}
@end
class2.m
@implementation class2
//i want to use the NSString in here, how do i do that?
谢谢,
雅各布
最佳答案
首先在类1中使用[string retain];
。
然后,在第2类中,导入class1。使类1的对象说cls1。您可以通过cls1.string;
访问它
关于iphone - 在类之间传递NSString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6909015/