首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Iphone >

Add subView 后subView不显示也不出错,求解,该怎么处理

2012-01-12 
Add subView 后subView不显示也不出错,求解我用navigationController从一个view跳到另外一个viewnavigatio

Add subView 后subView不显示也不出错,求解
我用navigationController从一个view跳到另外一个view

navigationController代码:

C/C++ code
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{    _detailController = [[WBDetailContentController alloc]init];     [self.navigationController pushViewController:_detailController animated:YES];        [_detailController release];}


跳转之后的viewDidLoad函数代码:
C/C++ code
- (void)viewDidLoad{    [super viewDidLoad];    self.title = @"test";    UIView *v = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]autorelease];//    UIView *v2 = [[[UIView alloc]initWithFrame:CGRectMake(1, 1, 10, 10)]autorelease];        self.view = v;    self.view.autoresizesSubviews = YES;    [v release];        _buttonForword = [[UIButton alloc]initWithFrame:CGRectMake(40, 150, 20, 10)];    _buttonComment = [[UIButton alloc]initWithFrame:CGRectMake(70, 150, 20, 10)];    _buttonMore = [[UIButton alloc]initWithFrame:CGRectMake(100, 150, 20, 10)];        _buttonMore.titleLabel.text = @"More";    _buttonComment.titleLabel.text = @"Comment";    _buttonForword.titleLabel.text = @"Forword";        [self.navigationController.view addSubview:_buttonForword];        [self.view addSubview:_buttonComment];    [self.view addSubview:_buttonForword];    [self.view addSubview:_buttonMore];        [_buttonForword release];    [_buttonComment release];    [_buttonMore release];}


跳转之后没一个按钮出现。求解!

谢谢!!!

[解决办法]
self.view = v;
改为[self.view addSubview:v];

其他按钮加到v上
[v addSubview: _buttonComment];
...

另外下面这句没用,同一个按钮不能同时加入两个view中
[self.navigationController.view addSubview:_buttonForword];
[解决办法]
非也……

显示出来了,只是你看不到而已。
 _buttonMore.titleLabel.text = @"More";
 
这种写法是不对的。 

UIButton 设置图片和标题是要跟状态对应的,看看文档就知道了。

把按钮的背景图换一下就显示出来了……

热点排行