[英]IOS Segue is not working in Custom Tab bar
i make my custom tab bar using segue it's run successfully , now i try to pass data between two view controller which is on tab bar view controller 我使用segue使我的自定义选项卡栏成功运行,现在我尝试在选项卡栏视图控制器上的两个视图控制器之间传递数据
my code for tab bar controller 我的标签栏控制器代码
- (void) perform {
ViewController *ctbcv = (ViewController *)self.sourceViewController;
UIViewController *dst = (UIViewController *) self.destinationViewController;
for(UIView *view in ctbcv.placeholder.subviews)
{
[view removeFromSuperview];
}
ctbcv.currentViewController = dst;
[ctbcv.placeholder addSubview:dst.view];
}
and segue condition 和隔离条件
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"HomeSegue"]
|| [segue.identifier isEqualToString:@"DeveloperSegue"]
|| [segue.identifier isEqualToString:@"DesignerSegue"]|| [segue.identifier isEqualToString:@"btn4"]){
NSLog(@"%lu",(unsigned long)[self.buttons.subviews count]);
for (int i=0; i<[self.buttons.subviews count];i++) {
UIButton *button = (UIButton *)[self.buttons.subviews objectAtIndex:i];
[button setSelected:NO];
}
UIButton *button = (UIButton *)sender;
NSLog(@"%ld", (long)button.tag);
btnclicked = button.tag;
[button setSelected:YES];
}
}
this code run successfully, now i create button on 1st view controller and give segue to the new view controller , it's crash when click on button. 此代码成功运行,现在我在第一个视图控制器上创建按钮,并将segue赋予新的视图控制器,单击按钮时崩溃。
- (void)viewDidLoad {
[super viewDidLoad];
[btnnext addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
}
-(void) buttonClicked:(UIButton*)sender
{
NSLog(@"you clicked on button %ld", (long)sender.tag);
[self performSegueWithIdentifier:@"MySegue" sender:sender];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"MySegue"]) {
navVC *vc = [segue destinationViewController];
}
}
After this code it crash and Xcode show "THREAD 1: EXC_BAD_ACCESS(code=2 , address = 0xc)" any solution ? 此代码崩溃后,Xcode显示“ THREAD 1:EXC_BAD_ACCESS(code = 2,address = 0xc)”任何解决方案吗?
i use this reference for making custom tab bar 我使用此参考制作自定义标签栏
i make button which open new view controller in this tab bar. 我在该选项卡栏中创建了用于打开新视图控制器的按钮。
Thank You 谢谢
只需检查一下您是否已将您的代码放在您要使用的主控制器中,而不是在标签栏控制器的标签中即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.