Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

didDeselectRowAtIndexPath does not get called on first row of UITableView [duplicate]

I am having a strange issue in my UITableView. Whenever I press the first row of my UITableView, the didDeselectRowAtIndexPath method doesn't get called. My current code for it is as follows.

# 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];
}
like image 274
DipakSonara Avatar asked Jun 24 '14 06:06

DipakSonara


1 Answers

Do you really mean didDeselectRowAtIndexPath?

No wonder, this is expected only didDeselectRowAtIndexPath will call only when you deselect a row that means when you make a change of selection. I suspect you mistakenly chosen didDeselectRowAtIndexPath. You may want to use didSelectRowAtIndexPath method

like image 50
Anil Varghese Avatar answered Oct 04 '22 22:10

Anil Varghese