-1

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を出力しますか???

前もって感謝します。

4

2 に答える 2

2

init で type を渡しますが、type を設定することはありません。どこかに保管する必要があります。初期状態

self.type = itype
于 2012-11-14T08:05:02.187 に答える
0

xib のビューのクラスを UIView から MDActionBar に変更します

于 2012-11-14T08:00:25.943 に答える