Add subView 后subView不显示也不出错,求解

iOS 码拜 9年前 (2015-05-06) 730次浏览 0个评论
 

我用navigationController从一个view跳到另外一个view

navigationController代码:

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

跳转之后的viewDidLoad函数代码:

- (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];
}

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

谢谢!

Add subView 后subView不显示也不出错,求解
30分
self.view = v;
改为[self.view addSubview:v];

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

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

Add subView 后subView不显示也不出错,求解
70分
非也……

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

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

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


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明Add subView 后subView不显示也不出错,求解
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!