didDeselectRowAtIndexPath

didDeselectRowAtIndexPath

This question already has an answer here:
When I select a UITableViewCell, my view controller label is an action behind

(1个答案)


已关闭6年。




我的UITableView中有一个奇怪的问题。每当我按UITableView的第一行时,就不会调用didDeselectRowAtIndexPath方法。我当前的代码如下。
# pragma  mark - UITableViewDelegate & UITableViewDataSource

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

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 80;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"TableCell";

    UIView *colorView,*backgroundView;
    UILabel *lblCode,*lblStatus,*lblDate;
    UITableViewCell *cell = (UITableViewCell *) [self.tbl_claims dequeueReusableCellWithIdentifier:CellIdentifier];
    cell = nil;
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    colorView = [[UIView alloc] initWithFrame:CGRectMake(7, 5, 5, 70)];
    [cell addSubview:colorView];

    backgroundView = [[UIView alloc] initWithFrame:CGRectMake(12, 5, 306, 70)];
    backgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"LightGreen"]];
    [cell addSubview:backgroundView];

    lblCode = [[UILabel alloc] initWithFrame:CGRectMake(20, 7, 140, 40)];
    lblCode.text = [[self.ary_tblDisplay objectAtIndex:indexPath.row] claim_code];
    lblCode.backgroundColor = [UIColor clearColor];
    lblCode.textColor = [UIColor blueColor];
    lblCode.font = [UIFont boldSystemFontOfSize:18];
    [cell addSubview:lblCode];

    lblStatus = [[UILabel alloc] initWithFrame:CGRectMake(20, 40, 140, 35)];
    lblStatus.backgroundColor = [UIColor clearColor];
    lblStatus.text = [[self.ary_tblDisplay objectAtIndex:indexPath.row] claim_status];
    [cell addSubview:lblStatus];

    lblDate = [[UILabel alloc] initWithFrame:CGRectMake(150, 20, 120, 40)];
    lblDate.backgroundColor = [UIColor clearColor];
    lblDate.text = [[self.ary_tblDisplay objectAtIndex:indexPath.row] accepted_date];
    [cell addSubview:lblDate];

    if ([lblStatus.text isEqualToString:@"Rejected"])
        colorView.backgroundColor = [UIColor redColor];
    else if ([lblStatus.text isEqualToString:@"Accepted"])
        colorView.backgroundColor = [UIColor greenColor];
    else if ([lblStatus.text isEqualToString:@"In-Progress"])
        colorView.backgroundColor = [UIColor blueColor];

    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.backgroundColor = [UIColor redColor];
    return cell;
}

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    StatusViewController *obj_StatusViewController = [[StatusViewController alloc] initWithNibName:IS_IPHONE_5?@"StatusViewController":@"StatusViewController_3.5" bundle:nil];
    obj_StatusViewController.details = [self.ary_tblDisplay objectAtIndex:indexPath.row];
    [self.navigationController pushViewController:obj_StatusViewController animated:YES];
}

最佳答案

您真的是说 didDeselectRowAtIndexPath 吗?

难怪,仅当您将取消选择表示要更改选择的行时,才预期只有didDeselectRowAtIndexPath会调用。我怀疑您错误地选择了didDeselectRowAtIndexPath。您可能要使用didSelectRowAtIndexPath方法

10-04 23:01