隐藏和取消隐藏工具栏时按钮项丢失
我不知道,为什么工具栏设置为隐藏和取消隐藏后按钮消失了。 我该如何修复它?
设置按钮代码
-(void)viewDidAppear:(BOOL)animated {
//NSLog(@"viewDidAppear ");
[self becomeFirstResponder];
//Create a button
UIBarButtonItem *back = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemRewind
target:self action:@selector(goback:)];
UIBarButtonItem *fixspace1 = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:self action:nil];
UIBarButtonItem *next = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFastForward
target:self action:@selector(gofwd:)];
UIBarButtonItem *stop = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemStop
target:self action:@selector(stopload:)];
UIBarButtonItem *refresh = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
target:self action:@selector(refreshWeb:)];
[self.navigationController.toolbar setItems:[NSArray arrayWithObjects:fixspace1, back, fixspace1, stop, fixspace1, next, fixspace1, nil] animated:YES];
[self.navigationItem setRightBarButtonItem:refresh animated:YES];
[self.navigationController.view addSubview:self.navigationController.toolbar];
[stop release];
[next release];
[back release];
[refresh release];
[fixspace1 release];
}
,我在此方法中设置按钮,
-(void)viewDidAppear:(BOOL)animated
此代码用于隐藏工具栏
[self.navigationController setNavigationBarHidden:YES animated:YES];
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
[self.navigationController setToolbarHidden:YES animated:YES];
i dont know, why the button are disappear after the toolbar set to hide and unhide.
how can i fix it?
setup a button code
-(void)viewDidAppear:(BOOL)animated {
//NSLog(@"viewDidAppear ");
[self becomeFirstResponder];
//Create a button
UIBarButtonItem *back = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemRewind
target:self action:@selector(goback:)];
UIBarButtonItem *fixspace1 = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:self action:nil];
UIBarButtonItem *next = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFastForward
target:self action:@selector(gofwd:)];
UIBarButtonItem *stop = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemStop
target:self action:@selector(stopload:)];
UIBarButtonItem *refresh = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
target:self action:@selector(refreshWeb:)];
[self.navigationController.toolbar setItems:[NSArray arrayWithObjects:fixspace1, back, fixspace1, stop, fixspace1, next, fixspace1, nil] animated:YES];
[self.navigationItem setRightBarButtonItem:refresh animated:YES];
[self.navigationController.view addSubview:self.navigationController.toolbar];
[stop release];
[next release];
[back release];
[refresh release];
[fixspace1 release];
}
and i setup my button at this method
-(void)viewDidAppear:(BOOL)animated
this code use for hide toolbar
[self.navigationController setNavigationBarHidden:YES animated:YES];
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
[self.navigationController setToolbarHidden:YES animated:YES];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是通过视图控制器的toolbarItems 属性。 相同的 UINavigationController Reference 还将
toolbar
属性列为只读并特别警告因此,尝试更改
为
The documented method for setting toolbar items is via the toolbarItems property of the view controller. The same UINavigationController Reference also lists the
toolbar
property as read-only and specifically warnsTherefore, try changing
to
看到没有更好的答案,我将推广我之前的评论。尝试去掉这一行:
我还没有尝试过类似的东西,但它看起来是错误的,并且非常违背 iPhone SDK 的理念。如果控制器对象已经有一个指向工具栏的指针,为什么需要将其添加到视图中?如果那是正确的位置,控制器对象就会自行执行此操作。
Seeing no better answers, I'll promote my earlier comment. Try taking out this line:
I haven't experimented with anything like that but it looks wrong and very much against the iPhone SDK philosophy. If the controller object already has a pointer to the toolbar, why would you need to add it to the view? If that's the right place for it, the controller object would do that itself.
我不认为您应该在将工具栏按钮添加到工具栏后立即释放它们。您应该将它们保存在实例变量中并在
dealloc
中释放它们。I doub't that you should release your toolbar buttons immediately after adding them to the toolbar. You should save them in instance variables and release them in your
dealloc
.