UISegmentedControl:ValueChanged处理程序上的EXC_BAD_ACCESS

时间:2012-10-22 13:37:38

标签: iphone ios uisegmentedcontrol

我想在我的应用程序UISegmentedControl中使用,以在Windows中制作类似于TabBar组件的东西。我使用ValueChanged Handler:

- (IBAction)tabBarChange:(id)sender{
    int pageId = tabBar.selectedSegmentIndex;
    // [self switchPage:pageId];
}

switchPage现在是空函数,没有写一行代码。

但是,在使用SegmentedControl时,会出现EXC_BAD_ACCESS异常。

我做错了什么?

2 个答案:

答案 0 :(得分:1)

tabBar是否真的在该函数中定义?不应该是:

int pageId = sender.selectedSegmentIndex;

答案 1 :(得分:0)

所以,我知道这种方法崩溃了:

- (IBAction)tabBarChange:(id)sender {
    [self switchPage:sender.selectedSegmentIndex];
}

如果您尝试在不传递任何参数的情况下创建一些测试函数,它是否会起作用,例如:

- (IBAction)tabBarChange:(id)sender {
    [self testFunction];
}

- (void) testFunction {
    NSLog(@"test");
}