IOS Segue在自定义标签栏中不起作用

时间:2014-12-01 09:42:59

标签: ios iphone uiviewcontroller segue

我使用segue成功运行我的自定义标签栏,现在我尝试在标签栏视图控制器上的两个视图控制器之间传递数据

我的标签栏控制器代码

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

和segue条件

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

此代码运行成功,现在我在第一个视图控制器上创建按钮并将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];

  }
 }

在此代码崩溃后,Xcode显示“THREAD 1:EXC_BAD_ACCESS(code = 2,address = 0xc)”任何解决方案?

我使用this reference制作自定义标签栏

我在此标签栏中创建打开新视图控制器的按钮。

谢谢

1 个答案:

答案 0 :(得分:1)

只是检查一下你是否已将代码放在要使用的主控制器中,而不是在标签栏控制器的标签中。