2013-12-08 3 views
0

저는 iOS 7에 있고, UITableView (UITableView) (데이터 소스와 위임자를 연결 함)를 사용하고 편집을 사용하려고합니다. UIStoryboard에서 Dynamice Prototype으로 사용자 정의 UITableViewCell을 사용합니다. 편집 버튼 (self.editButtonItem)을 클릭하면 이름 변경이 완료된 것을 볼 수 있지만 들여 쓰기 아이콘은 없습니다 (- 아이콘). 셀에서 스 와이프하면 삭제 버튼이 생깁니다. 사용자 정의 버튼을 만들 필요가 내의 모든 콘텐츠는 작동하지 않습니다 UIViewController에 self.editButtonItem에서있는 contentView사용자 정의 UITableViewCell이 들여 쓰기를 표시하지 않습니다.

+0

셀의 맞춤 콘텐츠가 셀의 'contentView'에 추가되고 셀에 직접 추가되지 않았는지 확인하십시오. – rmaddy

+0

제 질문을 추가했습니다. 그림을보십시오. –

+0

수정 버튼에 어떤 코드가 있습니까? – rdelmar

답변

3
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 


    if (editingStyle == UITableViewCellEditingStyleDelete) 
    { 
     [arr removeObjectAtIndex:indexPath.row]; 
     [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationBottom]; 
    } 
} 



- (IBAction)editbtn:(id)sender { 

    if (self.tableView.editing) { 
     self.tableView.editing = NO; 
     [edit setTitle:@"Edit" forState:UIControlStateNormal]; 
    } 
    else{ 
     self.tableView.editing = YES; 
     [edit setTitle:@"Done" forState:UIControlStateNormal]; 
    } 
} 

이 코드가 도움이된다고 생각합니다.

+0

이미 받으실 수 있습니다! 하지만이게 네가 사용할 수있는거야! –

-2

self.navigationItem.leftBarButtonItem = self.editButtonItem; 

// Override to support conditional editing of the table view. 
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Return NO if you do not want the specified item to be editable. 
    return YES; 
} 

// Override to support editing the table view. 
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (editingStyle == UITableViewCellEditingStyleDelete) { 
     // Delete the row from the data source 
     [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
    } 
    else if (editingStyle == UITableViewCellEditingStyleInsert) { 
     // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view 
    } 
} 

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { 
    return UITableViewCellEditingStyleDelete; 
} 

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

:

여기 내 코드입니다.

관련 문제