-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
NewsScreen *news=[[NewsScreen alloc] initWithNibName:@"NewsScreen" bundle:nil];
if (tabBarController.selectedIndex==2) {
[news.btn setHidden: YES];
}
NSLog(@"%@", tabBarController);
}
我想隐藏来自其他视图控制器的按钮。
答案 0 :(得分:2)
-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
if (tabBarController.selectedIndex==2)
{
NSUInteger *index=value; //assign value here
UINavigationController *nv = [[tabBarController viewControllers] objectAtIndex:index];//index of your NewsScreen controller
NSArray *array =[nv viewControllers];
for (ViewController *vc in array)
{
if ([vc isKindOfClass:[NewScreen class]])
{
[vc.btn setHidden:YES];
}
}
}
NSLog(@"%@", tabBarController);
}
答案 1 :(得分:0)
在BOOL
ViewController
中获取controller
变量并制作该属性。和synthesize
它也是。
然后这样做:
ViewController *vc = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
vc.check = YES;
在viewdidload
中写下这个:
if(self.check)
[mainbutton1 set hidden:YES];
<强>更新强>
如果您只想隐藏按钮,请尝试:
在Viewdidload
[button addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside];
-(void)btnClicked
{
[button setHidden:YES];
}
答案 2 :(得分:0)
将您的代码更改为:
-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
NewsScreen *news= (NewsScreen*) [tabBarController.viewControllers objectAtIndex:1]; // Replace 1 with your NewsScree View Controller's index thats your tab number - 1.
if (tabBarController.selectedIndex==2) {
[news.btn setHidden: YES];
}
}