2011-12-23 123 views
0

我正在创建一个简单的应用程序来从UITable中选择视频网址。我已经挂钩了我的数据源和委托给UIViewController子类,并且表格被正确填充。此外,它可识别选择并打印到日志。随机UITable选择填充表时的代理崩溃

我的问题是,当我选择一个单元格时,它会得到一个“EXC_BAD_ACCESS”并崩溃。我期待通过代码和错误传播到这个方法:

-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString* cellIdentifier = @"SelectionIdentifier"; 

    //Errors start happening this next line 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 
    if(cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease]; 
    } 
    //NSString* str = [[videos objectAtIndex:[indexPath row]] lastPathComponent]; 
    NSString* test = @"test"; 
    [[cell textLabel] setText:test]; 
    return cell; 
} 

-(void) tableView:(UITableView*)myTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
// NSLog(@"Selected!"); 
} 

-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section { 
    return [videos count]; 
} 

我不知道为什么这个错误是在这种方法得到抛出。任何修复?我仔细检查,以确保视频阵列不是没有。

我做了另一个应用程序,使用这种相同的方法,它不会导致这些错误。

任何帮助或建议将不胜感激!

+0

你可以继续并显示一些其他表函数的代码?另外,请确保代表安装得当。 – 2011-12-23 21:55:19

+0

当然。我已经更新了这些方法。这些是我为委托和数据源实施的唯一方法。我还仔细检查了故事板上的连接。 – user1035839 2011-12-23 22:07:29

+0

我把它声明为IBOutlet UITableView * tableView; – user1035839 2011-12-23 22:20:44

回答

0

而不是测试如果(cell == nil)尝试使用if(!cell)。老实说,我不确定这是否是问题,但在回顾了这个之后,我并不认为这个错误实际上并不在这个方法中(它可能在某种程度上是相关的,这就是为什么它会把你带到这里)。

如果这只是在您选择一个单元格之后,为什么要调用此方法?

+0

我原本有(!cell),但改回它仍然使错误发生。我不确定为什么这个方法会被要求说实话。 didSelectRowAtIndexPath方法是空白的,目前不做任何事情。 – user1035839 2011-12-23 21:44:14

0

我想你也应该把这个method.Because这是初步的委托方法

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
return 1; 
} 

看到您的tableView我没有发现在all.Try可能将解决任何问题之后。