2012-06-05 2 views
0

내가 셀을 클릭하면 색상이 바뀌어야하고 색상이 해당 셀에 남아 있어야합니다. 여기에서 내가 성공했습니다.하지만 테이블이 새로 고칠 때 다음 셀 배경 색상 내가 잘못 어디에 사라 당신이 원하는 경우 코드ipad에서 클릭 할 때 셀 배경색 또는 이미지를 변경하는 방법

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 

     //here i create view with color for cell when cell is click this view should display as background i am write or wrong by doing this please help me here why my view is disappear when my tableview is refresh then this view is disapper from cell i want to stay that place till user not click other cell&mt tableview is grouped tableview. 
     UIView *v = [[[UIView alloc] init] autorelease]; 
     v.layer.cornerRadius =6.0f; 
     v.backgroundColor = [UIColor darkGrayColor]; 
     cell.selectedBackgroundView = v; 
     } 
    return cell; 
} 



- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { 
    if (indexPath.row == 0 || indexPath.row%1 == 0) { 
     UIColor *altCellColor = [UIColor colorWithWhite:0.2 alpha:0.1]; 
     cell.backgroundColor = altCellColor; 

    } 


} 

답변

0

의 일부 라인을 그리워 내가 사과 문서에서 코드 내가이 .I를 사용있어이 날 도움이 선택한 유지하도록하십시오 행을 새로 고침하면 선택한 indexPath를 저장하고 다음 방법을 사용할 수 있습니다.

NSIndexPath *rowToSelect; //save your selected indexPath 

[myTableView selectRowAtIndexPath:rowToSelect animated:YES scrollPosition:UITableViewScrollPositionNone; 
[myTableView scrollToRowAtIndexPath:rowToSelect atScrollPosition:UITableViewScrollPositionNon animate:YES]; 
+0

안녕하세요 친구 어디서이 코드를 사용하려면 셀렉션 방법을했는데 셀이 선택되면 충돌이 발생합니다 – Rocky

+0

indexPath를 didSelect 메서드에 저장하고 cellForRowAtIndexPath.and에서 위의 메서드를 호출해야합니다. 충돌 로그를 표시 할 수 있습니까? –

+0

ipad에서 spliteview 응용 프로그램을 만들고 있습니다. 왼쪽보기는 tableview 및 오른쪽보기입니다. 선택한 데이터를 새로 추가 할 때 모든 데이터 항목이 표시됩니다. 선택한 셀 색이 새로 고침되고 셀에서 사라집니다. – Rocky

관련 문제