your programing

uitableview 삭제 버튼 텍스트를 변경하는 방법

lovepro 2020. 10. 15. 08:21
반응형

uitableview 삭제 버튼 텍스트를 변경하는 방법


안녕하세요, 사용자가 내 테이블 뷰 내부에서 uitableviewcell을 스 와이프 할 때 삭제 버튼에 표시되는 텍스트를 변경하려고합니다.

이 tableview 대리자를 사용하라는 다른 질문 스레드의 예를 보았습니다.

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath

제 질문은이 방법을 어떻게 사용 하는가입니다.이 방법을 사용하는 방법을 잘 모르겠습니다.


컨트롤러에서를 관리하고 메서드 내에서 원하는 제목을 UITableView구현 UITableviewDelegate하고 반환 해야합니다 titleForDeleteConfirmationButtonForRowAtIndexPath.

예:

@interface CategoryAddViewController : UITableViewController
@end

@implementation CategoryAddViewController
// ...
-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
return @"Please don't delete me!";
}

@end

다음과 같이 당신을 떠나십시오.

여기에 이미지 설명 입력


Swift에서는 동일하며 메서드 서명 만 다릅니다!

func tableView(tableView: UITableView, titleForDeleteConfirmationButtonForRowAtIndexPath indexPath: NSIndexPath) -> String? {
  return "Erase"
}

삭제 대신 표시하려는 문자열을 반환하십시오. 모든 행에 대해 "지우기"를 표시하려면 위 함수에 다음이 포함되어야합니다.

return @"Erase";

이것을 읽으십시오

또한 .h 파일에서 뷰 컨트롤러가 이미 UITableViewController가 아닌 경우 UITableViewDelegate를 추가하십시오. 다음 중 하나 일 수 있습니다.

@interface SomeView : UIViewController <UITableViewDelegate>

또는

@interface SomeView : UITableViewController

참고 URL : https://stackoverflow.com/questions/7394988/how-to-change-uitableview-delete-button-text

반응형