Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.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 UIScrollview不添加按钮_Iphone_Uiscrollview_Uibutton - Fatal编程技术网

Iphone UIScrollview不添加按钮

Iphone UIScrollview不添加按钮,iphone,uiscrollview,uibutton,Iphone,Uiscrollview,Uibutton,我定义了一个uiscrollview,并使用for循环向其添加按钮,但每当我运行该程序时,都会出现一个空白屏幕。 这是我的viewDidLoad,这是所有与此相关的代码 - (void)viewDidLoad { [super viewDidLoad]; scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 1000)]; scrollView.hidden = NO; name

我定义了一个uiscrollview,并使用for循环向其添加按钮,但每当我运行该程序时,都会出现一个空白屏幕。 这是我的viewDidLoad,这是所有与此相关的代码

- (void)viewDidLoad
{
    [super viewDidLoad];
    scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 1000)];
    scrollView.hidden = NO;
    names = [[NSMutableArray alloc]initWithObjects:@"Excavations",@"Concrete",@"Framing",@"Insulation",@"Drywall",@"Finish Carpentry",@"Paint",@"Electrical",@"HVAC",@"Plumbing",@"Roofing",@"Tile",@"Doors",@"Windows",@"Flooring",@"Countertops",@"Landscape",@"Hardscape", nil];
    for (int i = 0; i < 18; i++) {
        UIButton *button = [[UIButton alloc]init];
        button.frame = CGRectMake(0, 50*i, 320, 50);
        button.tag = i;
        [button addTarget:self action:@selector(NewView:) forControlEvents:UIControlEventTouchUpInside];
        button.titleLabel.text = [names objectAtIndex:i];
        button.hidden= NO;
        [scrollView addSubview:button];
    }

// Do any additional setup after loading the view, typically from a nib.
}
-(void)viewDidLoad
{
[超级视图下载];
scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0,0321000)];
scrollView.hidden=否;
名称=[[NSMUTABLEARY alloc]initWithObjects:“挖掘”、“混凝土”、“框架”、“隔热”、“干墙”、“饰面木工”、“油漆”、“电气”、“暖通空调”、“管道”、“屋顶”、“瓷砖”、“门”、“窗”、“地板”、“台面”、“景观”、“硬景观”,零];
对于(int i=0;i<18;i++){
UIButton*按钮=[[UIButton alloc]init];
button.frame=CGRectMake(0,50*i,320,50);
button.tag=i;
[按钮添加目标:自我操作:@selector(NewView:)forControlEvents:UIControlEventTouchUpInside];
button.titleLabel.text=[names objectAtIndex:i];
按钮。隐藏=否;
[滚动视图添加子视图:按钮];
}
//加载视图后,通常从nib执行任何其他设置。
}

您需要手动设置按钮的类型,或仅用它初始化:

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
编辑:您还忘记将滚动视图添加到主视图

[self.view addSubview:scrollView];

您需要手动设置按钮的类型,或仅使用它进行初始化:

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
编辑:您还忘记将滚动视图添加到主视图

[self.view addSubview:scrollView];

您必须将UIScrollView添加到视图中。试一试

...
scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 1000)];
scrollView.hidden = NO;
[self.view addSubview:scrollView]; 
...

您必须将UIScrollView添加到视图中。试一试

...
scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 1000)];
scrollView.hidden = NO;
[self.view addSubview:scrollView]; 
...

就这样。我尝试了[自我添加子视图],但没有成功。我想我需要指定self的视图部分,就是这样。我尝试了[自我添加子视图],但没有成功。我想我需要指定self的视图部分。