试图将 UIButton 添加到 UIView 但得到 NSInvalidArgumentException',原因:'-[UIView addSubView:]: 无法识别 [英] Trying to add a UIButton to a UIView but getting NSInvalidArgumentException', reason: '-[UIView addSubView:]: unrecognized

查看:34
本文介绍了试图将 UIButton 添加到 UIView 但得到 NSInvalidArgumentException',原因:'-[UIView addSubView:]: 无法识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 UIButton 添加到 UIView,但在运行时出现此错误.

I'm trying to add a UIButton to a UIView but I'm getting this error at runtime.

NSInvalidArgumentException',原因:'-[UIView addSubView:]:无法识别

NSInvalidArgumentException', reason: '-[UIView addSubView:]: unrecognized

XCode 还警告我

实例方法 '-addSubView:' 未找到(返回类型默认为'id')

Instance method '-addSubView:' not found (return type defaults to 'id')

这是我的代码:

 UIView *trackPaneView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 768, 100)] autorelease];
    [trackPaneView setBackgroundColor:[UIColor blueColor]];

UIButton *testButton = [[UIButton alloc] initWithFrame:CGRectMake(100, 10, 100, 30)];
    [testButton setTitle:@"AWESOME" forState:UIControlStateNormal];
    [trackPaneView addSubView:testButton];  //the error coming form this line

推荐答案

方法是addSubview:不是addSubView:

The method is addSubview: not addSubView:

(大写错误)

这篇关于试图将 UIButton 添加到 UIView 但得到 NSInvalidArgumentException',原因:'-[UIView addSubView:]: 无法识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆