Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何实现loadView?_Iphone_Objective C_Cocoa Touch_Ios_Loadview - Fatal编程技术网

Iphone 如何实现loadView?

Iphone 如何实现loadView?,iphone,objective-c,cocoa-touch,ios,loadview,Iphone,Objective C,Cocoa Touch,Ios,Loadview,我创建了一个名为GraphView的自定义视图。加载视图时,我得到的只是一个空白的黑屏。这是我的密码: 在GraphViewController.m中: @synthesize graphView, graphModel; - (void)loadView { GraphView *aGraphView = [[GraphView alloc] initWithFrame:CGRectZero]; self.view = aGraphView; self.grap

我创建了一个名为
GraphView
的自定义视图。加载视图时,我得到的只是一个空白的黑屏。这是我的密码:

在GraphViewController.m中:

@synthesize graphView, graphModel;

- (void)loadView
{   
    GraphView *aGraphView = [[GraphView alloc] initWithFrame:CGRectZero];
    self.view = aGraphView;
    self.graphView = aGraphView;

    [aGraphView release];
}

我不知道为什么在
GraphViewController.m
中尝试实现
loadView
时会出现黑屏,因为您没有为
GraphView
对象设置帧:

GraphView*aGraphView=[[GraphView alloc]init]

UIView
的指定初始值设定项是
-initWithFrame:
。执行以下操作(根据需要设置视图的大小/原点):


GraphView*aGraphView=[[GraphView alloc]initWithFrame:CGRectMake(0,0,100,100)]

我需要在
加载视图中将背景颜色设置为白色

- (void)loadView
{   
    GraphView *aGraphView = [[GraphView alloc] initWithFrame:CGRectZero];
    aGraphView.backgroundColor = [UIColor whiteColor];
    self.view = aGraphView;
    self.graphView = aGraphView;

    [aGraphView release];
}

我做了指定的更改,但它仍然显示一个空白的黑屏。我注释掉了
loadView
,现在它仍然可以工作,即使我删除了以前使用的.xib文件。如果没有.xib或
loadView
,我对它如何工作感到困惑。您还需要清理部署的应用程序。删除模拟器或设备上的应用程序。清除所有目标。运行应用程序。然后你会看到它是如何工作的。我如何“清理所有目标等”?好的,我做了一个新项目并复制了文件,现在当我对loadView进行注释时,我会看到一个空白的白色屏幕。如果我实现loadView,那么我会得到一个空白的黑屏。我将发布我的
graphView.m