我已经创建了两个的viewController类,一个是another.i的超有超一的NSString变量,我在子类中访问,请指导我该怎么做。这里是我的代码如何访问超变量在子类中
@interface Superclass : UIViewController{
NSString *message
}
@property(nonatomic,retain)NSString *message;
-(id)init;
@end
@implementation Superclass
@synthesize message;
-(id)init{
{
[super init];
[email protected]"Hello";
return self;
}
@interface Subclass : Superclass{
}
@end
@implementation Subclass
- (void)viewDidLoad {
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Alert" message:self.message delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
[alert show];
[alert release];
[super viewDidLoad];
}
我的警报promt但没有消息。
是的,使用initWithNibname:绑定: – NoviceDeveloper 2012-03-26 13:07:23
之后,使用'消息'的超类'对象,无论你想访问它...像superclass.message ... :) – Krunal 2012-03-26 13:10:10
你还需要保留消息在你的超类 – 2012-03-26 13:11:06