【发布时间】:2012-11-02 17:00:33
【问题描述】:
我创建了三个文件,有
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 中没有 'type' 属性,那么它会打印 null???
提前致谢。
【问题讨论】:
-
你什么时候打电话给
NSLog(@"_type %@",self.type);? -
@JackyBoy,谢谢。我用另一种方法调用它:- (IBAction)fn_pressedButton:(id)sender { NSLog(@"_type %@",self.type);}
标签: iphone ios uiview properties xib