3 つのファイルを作成します。
MDActionBar.h,
MDActionBar.m,
MDActionBar.xib
MDActionBar.h
#import <UIKit/UIKit.h>
@interface MDActionBar : UIView{
NSString* _type;
}
@property (retain, nonatomic) IBOutlet UIButton *label_tips;
@property (nonatomic,retain) NSString* type;
-(id)initWithFrame:(CGRect)frame;
@end
MDActionBar.m
#import "MDActionBar.h"
@implementation MDActionBar
@synthesize type = _type;
-(id)initWithFrame:(CGRect)frame withType:(NSString*)itype{
self = [super initWithFrame:frame];
if (self) {
[[NSBundle mainBundle] loadNibNamed:@"MDActionBar" owner:self options:nil];
NSArray *theView = [[NSBundle mainBundle] loadNibNamed:@"MDActionBar" owner:self options:nil];
self = [theView objectAtIndex:0];
self.frame = frame;
}
}
そして、このクラスを次のように使用します。
MDActionBar* mdActionBar = [[[MDActionBar alloc]initWithFrame:UI_TOOLBAR_POSITION_DOWN withType:@"done"] autorelease];
mdActionBar.type = @"done";
MDActionBar.m に「type」という名前のプロパティがないようです。
NSLog(@"_type %@",self.type);
コンソールには常に null が表示されます。
xibをロードし、このxibがUIViewであり、UIViewに「タイプ」プロパティがない場合、nullを出力しますか???
前もって感謝します。