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

sunshine_anycall 2011-11-06 02:55:36
我用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];
}


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

谢谢!!!
...全文
264 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
咸清 2011-11-06
  • 打赏
  • 举报
回复
非也……

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

这种写法是不对的。

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

把按钮的背景图换一下就显示出来了……
巴依老爷 2011-11-06
  • 打赏
  • 举报
回复
self.view = v;
改为[self.view addSubview:v];

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

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

29,048

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧