2012-09-20 3 views
0

시간이 지나면 UITableView에서 셀을 reoder하는 기능을 시도합니다.UITableView에서 셀을 재정렬하는 방법

나는 세포

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

UITableViewCell *cell = [tV dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
} 

// Set up the cell... 



cell.textLabel.text = [array objectAtIndex:indexPath.row]; 
cell.showsReorderControl = YES; 
return cell; 
} 

을 만들고 난이있어 :

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { 
return YES; 
} 

버튼 방법

- (IBAction)delete:(id)sender { 
if (self.btnLeft.tag == 0) { 
    self.btnLeft.title = @"Zakończ"; 
    [self.tableView setEditing:YES animated:YES]; 
    self.btnLeft.tag = 1; 
} 
else if (self.btnLeft.tag == 1) { 
    self.btnLeft.title = @"Edytuj"; 
    [self.tableView setEditing:NO animated:YES]; 
    self.btnLeft.tag = 0; 
} 
} 

내가 편집 버튼 전을 setEditing to YES을 클릭 만하면하지만 난 할 수 재정렬이 아니라 행만 삭제하십시오. 언제 오류가 있습니까? 내 말은 오른쪽 셀쪽에 재주문 아이콘이 없다는 뜻입니다.

답변

1

좋아, 해결 했어.

재정렬 제어가 나타나게하려면이 속성을 설정해야 할뿐만 아니라 UITableViewDataSource 메서드 tableView : moveRowAtIndexPath : toIndexPath :를 구현해야합니다. 또한 데이터 소스가 tableView : canMoveRowAtIndexPath :를 구현하여 NO를 반환하면 순서 지정 컨트롤이 지정된 행에 표시되지 않습니다.

+0

나는 스스로 죽일거야 - 나는이 방법들을 가지고있다. cell.showsReorderControl = YES; 각 셀 클래스에 대해 ...하지만 재정렬 컨트롤러가 나타나지 않습니다 : / – raistlin

관련 문제