我在一个xib文件中创建了一个视图(包含活动指示器、进度条和标签)。然后我创建了.h/.m文件:
#import <UIKit/UIKit.h>
@interface MyCustomView : UIView {
IBOutlet UIActivityIndicatorView *actIndicator;
IBOutlet UIProgressView *progressBar;
IBOutlet UILabel *statusMsg;
}
@end
#import "MyCustomView.h"
@implementation MyCustomView
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
// Initialization code
}
return self;
}
- (void)dealloc {
[super dealloc];
}
@end
在 IB 中,我将文件所有者和视图身份设置为 MyCustomView,并将 IBOutlet 连接到文件的所有者
在 MyViewController.m 中,我已经:
- (void)viewDidLoad {
[super viewDidLoad];
UIView *subView = [[MyCustomView alloc] initWithFrame:myTableView.frame];
[subView setBackgroundColor:[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.5]];
[myTableView addSubview:subView];
[subView release];
}
当我运行应用程序时,视图被添加了,但是无法看到标签、进度条和活动指示器。我做错了什么?
initWithCoder:
的提示。我无法弄清楚我的自定义视图是如何创建的,没有调用init
或initWithFrame
。 - Christopher Pickslay