执行willSelectRowAtIndexPath后生成的EXC_BAD_ADRESS

Kir*_*rov 0 cocoa-touch objective-c

为什么在执行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];
        }
    }
Run Code Online (Sandbox Code Playgroud)

Flo*_*lke 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;
}
Run Code Online (Sandbox Code Playgroud)

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