2013-04-06 107 views
-1

我试图创建这个应用程序,当你按一个tablecell时显示ViewController,而变量get的设置在另一个视图控制器中。尽管当我按下uitablecell时,出现了一些错误。Objective C - [__ NSCFString _isAncestorOfFirstResponder]错误

错误:

2013-04-06 22:47:25.970 iFSX Guide[1069:907] Called 
2013-04-06 22:47:26.009 iFSX Guide[1069:907] -[__NSCFString  _isAncestorOfFirstResponder]: unrecognized selector sent to instance 0x1d562390 
2013-04-06 22:47:26.016 iFSX Guide[1069:907] *** Terminating app due to uncaught  exception 'NSInvalidArgumentException', reason: '-[__NSCFString _isAncestorOfFirstResponder]: unrecognized selector sent to instance 0x1d562390' 
*** First throw call stack: 
(0x319b22a3 0x3964c97f 0x319b5e07 0x319b4531 0x3190bf68 0x33832beb 0x338a837f 0x338548fb 0x33a95619 0x338a79b9 0x338a5fe7 0x339c83ef 0xa22a5 0x3387c28d 0x338fef81 0x322c0277 0x319875df 0x31987291 0x31985f01 0x318f8ebd 0x318f8d49 0x354ba2eb 0x3380e301 0xa19d1 0x39a83b20) 
libc++abi.dylib: terminate called throwing an exception 

代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)in dexPath{ 
    NSLog(@"Called"); 
    Aircraft = indexPath.row; 

    [self performSegueWithIdentifier:@"ToSections" sender:self]; 

} 

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ 
    if([segue.identifier isEqualToString:@"ToSections"]){ 
     AirplaneSections *sections = (AirplaneSections *)segue.destinationViewController; 
     sections.plane = Aircraft; 
    } 
} 

我发现,它是在视图控制器viewDidLoad方法上的错误。

NSString *quickTemp = [NSString alloc]; 
switch (plane) { 
    case 0: 
     quickTemp = @"Boeing 737-800"; 
     break; 

    default: 
     break; 
} 
TitleLabel.text = quickTemp; 
*/ 

我在那里做错了。

+0

'飞机'是什么样的属性?你在使用ARC吗? – omz 2013-04-06 20:54:33

+0

飞机是一个“int”,是的,我使用ARC – 2013-04-06 21:19:29

回答

0

您是否使用ARC?这类问题通常表明某处存在内存错误。基本上,某处的某些代码试图访问已经发布的对象。这使得所有事情都变成了kaboom。

如果你不使用ARC,你应该打开它。

之后,你应该做的下一件事是运行静态分析器。修复出现的任何问题。

如果这样不能解决问题,请在Xcode中添加一个断点,以便在引发Objective-C异常时停止。它应该告诉你究竟发生了什么问题。

如果这没有帮助,请在“乐器”和“僵尸”工具下运行您的代码。这会向您显示刚好您试图访问已释放的内存的位置。

+0

我发现performSegue是问题,当我评论它的应用程序的作品,但是当它在那里它剂量.... – 2013-04-06 22:06:10

+0

@JackyBoy:这确实看起来像ARC帮助避开的那种内存管理错误,所以这是一个有效的建议。 – Chuck 2013-04-06 22:35:16