我在 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];
}
当我运行应用程序时,添加了视图,但我看不到标签、进度条和活动指示器。
我究竟做错了什么?