簡體   English   中英

Tableview單元格選擇問題

[英]Tableview cell selection problem

您好,我正在使用分組表視圖並選擇具有blueselection樣式的Tableview單元格。

但是當選擇單元格並轉到下一個視圖並再次返回到上一個視圖時,該單元格仍處於選中狀態,如果我選擇另一個單元格,則顯示2個單元格處於選中狀態。

在我的代碼中看到下面的圖片:

在此處輸入圖片說明

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";
    JobViewTableCell *cell = (JobViewTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
            [[NSBundle mainBundle] loadNibNamed:@"iPadJobViewCell" owner:self options:nil];
            cell = self.JobViewcell;
        }
        else {
        [[NSBundle mainBundle] loadNibNamed:@"JobViewTableCell" owner:self options:nil];
        cell = self.JobViewcell;

        }
    }


    [cell setJobID:[NSString stringWithFormat: @"%@",[(Jobs *)[tableArray objectAtIndex:indexPath.row]JobId]]];
    [cell setJobTitle:[NSString stringWithFormat:@"%@",[(Jobs *)[tableArray objectAtIndex:indexPath.row]Title]]];

    NSString *newDate =[NSString stringWithFormat:@"%@",[(Jobs *)[tableArray objectAtIndex:indexPath.row]Date]];

    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"MM/dd/yyyy h:mm:ss a"];
    NSDate *myDate = [dateFormat dateFromString:newDate];
    [dateFormat setDateFormat:@"MM/dd/yyyy"];

    NSString *str = [dateFormat stringFromDate:myDate];

    NSLog(@"%@",str);



    [cell setJobDate:[NSString stringWithFormat:@"%@",str]];
    [cell setLocation:[NSString stringWithFormat:@"%@",[(Jobs *)[tableArray objectAtIndex:indexPath.row]Location]]];
    [dateFormat release];
    return cell;
}

請幫忙

在tableView的didSelectRowAtIndexPath方法中,添加deselectRowAtIndexPath

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    [tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:NO];
    . . .
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM