3

在我的项目中,我有一个自定义的 @interface GraphView: UIView。因此GraphView是一个子类,UIView旨在显示一个图形。

Summary然后,我使用 NIB创建了一个新的视图控制器。在界面生成器中,我只是UIToolbar在视图底部添加了一个。

在方法的实现中SummaryviewDidLoad我有以下代码:

-(void)viewDidLoad {
  [super viewDidLoad];
  GraphView *myGraph = [[GraphView alloc]init];
  [self.view addSubview:myGraph]; //this does not work
}

但我无法得到这个。

4

1 回答 1

3

我相信您需要myGraph在将其作为子视图添加到self.

CGRect rect = CGRectInset(self.view.bounds, 0.0, 0.0);
GraphView *myGraph = [[GraphView alloc] initWithFrame:rect];
[self.view addSubview:myGraph];
于 2010-09-24T00:30:14.073 回答