我有一个 UIviewController。我想添加一个 UIView 作为子视图,但是由于 UIView 没有 viewdidload 方法,我需要手动调用一个方法。我以这种方式使用共享单例来执行此操作:
在 view.mi 中有:
+ (TableLoadGroupMembersViewController *)sharedManager
{
static TableLoadGroupMembersViewController *shaderManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
shaderManager = [[TableLoadGroupMembersViewController alloc] init];
});
return shaderManager;
}
- (void)LoadTheView
{
TableViewGroupMembers = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
TableViewGroupMembers.dataSource = self;
TableViewGroupMembers.delegate = self;
[TableViewGroupMembers addSubview:TableViewGroupMembers];
}
在 view.h 我有
+ (TableLoadGroupMembersViewController *) sharedManager;
- (void)LoadTheView;
在 viewcontroller.m 我有:
CGRect frame = CGRectMake(100, 100, 300, 100);
TableLoadGroupMembersViewController *view = [[TableLoadGroupMembersViewController alloc] initWithFrame:frame];
[self.view addSubview:view];
TableLoadGroupMembersViewController* sharedSingleton = [TableLoadGroupMembersViewController sharedManager];
[sharedSingleton LoadTheView];
但应用程序崩溃。为什么?
编辑:
错误是:0x281db5d: pushl %esi ... 线程 1: EXC_BAD_ACCESS