我已經創建了兩個的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