0

为什么在 willSelectRowAtIndexPath 执行之后和 didSelectRowAtIndexPath 之前生成 EXC_BAD_ADRESS?如果没有 willSelectRowAtIndexPath 实现,它可以完美运行。

这是我的代码:

 - (void)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        KMWTableViewCell *cell = (KMWTableViewCell *) [tableView cellForRowAtIndexPath:indexPath];
        if(cell){
            cell.visibleView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"cellBackPressed.png"]];
        }
    }

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        KMWTableViewCell *cell = (KMWTableViewCell *) [tableView cellForRowAtIndexPath:indexPath];
        if(cell){
            [self setCurrentAccountId:[[[KMWAppDelegate accounts] objectAtIndex:indexPath.section] objectForKey:@"accountId"]];
            [self performSegueWithIdentifier:@"services" sender:self];
        }
    }
4

1 回答 1

5

方法签名错误。它的返回值应该是NSIndexPath

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    KMWTableViewCell *cell = (KMWTableViewCell *) [tableView cellForRowAtIndexPath:indexPath];
    if(cell){
        cell.visibleView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"cellBackPressed.png"]];
    }

    return indexPath;
}

在您的实现中,您最终需要返回给定的indexPath.

于 2013-07-23T14:59:10.503 回答