【发布时间】:2012-09-18 13:41:34
【问题描述】:
我想在 classB 中创建一个 UIView,从 classA 调用以显示在 MainView(我的 UIViewController)上。
谁能帮我修复我的代码?
A 类:
+ (void)trigger
{
[classB viewOn:[MainView new]];
}
B 类:
+ (void)viewOn:(id)sender
{
MainView *pointer = (MainView *)sender;
classB *view = [[classB alloc] initWithFrame:CGRectMake(380, 200, 100, 50)];
view.backgroundColor = [[UIColor greenColor] colorWithAlphaComponent:0.5f];
view.userInteractionEnabled = YES;
UILabel *lab = [UILabel new];
lab.frame = CGRectMake(0, 0, 100, 50);
lab.text = @"test";
[view addSubview:lab];
[pointer.view addSubview:view];
}
当我使用 MainView 类通过 [classB viewOn:self] 调用 classB 时,它工作正常。但是如果我想从classA触发它,我该怎么做呢?
【问题讨论】:
标签: iphone objective-c xcode uiview uiviewcontroller