【发布时间】:2013-06-05 13:51:39
【问题描述】:
我有一个 UIViewController 的子类,我们称之为 MySuperClass ,这个子类有一个 UITableView 属性,它不是以编程方式初始化的。 现在我想将 MySuperClass 子类化为 MySubclass 但这次我想通过 Interface Builder 而不是以编程方式设计 tableview。 我想要的是类似于 UIViewController 工作方式的东西,如果您将 UIViewController 子类化,它的视图属性已经初始化,但是当您将它带入 IB 时,您可以将其链接到 Interface Builder 的 UIView 项目,如何我这样做?
我的超类的源代码和这个类似:
//interface
#import <UIKit/UIKit.h>
@interface MySuperClass : UIViewController <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
//implementation
#import "MySuperClass.h"
@implementation MySuperClass
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
[self initializeProperties];
}
return self;
}
- (void) awakeFromNib{
[super awakeFromNib];
[self initializeProperties];
}
- (void) initializeProperties{
self.tableView = [[UITableView alloc] initWithFrame: self.view.frame style: UITableViewStylePlain];
self.tableView.separatorColor = [UIColor clearColor];
self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.delegate = self;
self.tableView.dataSource = self;
UIView *tableHeaderView = [[UIView alloc] initWithFrame: CGRectMake(0, 0, self.view.frame.size.width, self.bannerView.frame.size.height+kBannerDistance)];
tableHeaderView.backgroundColor = [UIColor clearColor];
self.tableView.tableHeaderView = tableHeaderView;
}
【问题讨论】:
标签: ios objective-c uiviewcontroller interface-builder iboutlet