UITableView에서 빈 셀을 제거하는 방법은 무엇입니까? [복제]
이 질문에는 이미 답변이 있습니다.
- UITableView 33 답변 아래에서 추가 구분 기호 제거
UITableView일부 데이터 로 단순을 표시하려고합니다 . UITableView테이블 끝에 빈 셀이 표시되지 않도록 정적 높이를 설정하고 싶습니다 . 어떻게합니까?
암호:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"%d", [arr count]);
return [arr count];
}
다음과 같이 높이가 0 인 테이블 바닥 글보기를 설정하십시오 (아마도 viewDidLoad방법에서).
빠른:
tableView.tableFooterView = UIView()
목표 -C :
tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
표에는 표시 할 바닥 글이 있다고 생각하기 때문에 명시 적으로 요청한 것 이외의 셀은 표시되지 않습니다.
인터페이스 빌더 팁 :
xib / Storyboard를 사용하는 경우 UIView (높이 0pt)를 UITableView의 맨 아래로 드래그하면됩니다.
스위프트 3 구문 :
tableView.tableFooterView = UIView(frame: .zero)
신속한 구문 : <2.0
tableView.tableFooterView = UIView(frame: CGRect.zeroRect)
스위프트 2.0 문법 :
tableView.tableFooterView = UIView(frame: CGRect.zero)
스토리 보드에서을 선택하고 UITableView스타일 속성을에서 Plain로 수정하십시오 Grouped.
Xcode 6.1에서 신속하게 구현
self.tableView.tableFooterView = UIView(frame: CGRectZero)
self.tableView.tableFooterView?.hidden = true
두 번째 코드 줄은 프리젠 테이션에 영향을 미치지 않으며, 숨겨져 있는지 여부를 확인하는 데 사용할 수 있습니다.
이 링크에서 가져온 답변 UITableView Swift에서 빈 셀을 숨기지 못함
지금은 의견을 추가 할 수 없으므로이 답변을 추가하십시오.
@ 앤디의 대답은 좋고 다음 코드 줄을 사용하여 동일한 결과를 얻을 수 있습니다.
tableView.tableFooterView = [UIView new];
'새로운'방법에 속하는 NSObject클래스를 발동 alloc및 init방법 UIView.
나는 코드를 시도했다 :
tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
에서 의 viewDidLoad의 부와 xcode6 경고를 보여 주었다. 나는 "자기"를 넣었습니다. 그것의 앞에 지금은 잘 작동합니다. 그래서 내가 사용하는 작업 코드는 다음과 같습니다
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
또는 tableView 메서드를 호출하여 바닥 글 높이를 1 포인트로 설정하면 마지막 줄이 추가되지만 바닥 글 배경색을 설정하여 숨길 수도 있습니다.
암호:
func tableView(tableView: UITableView,heightForFooterInSection section: Int) -> CGFloat {
return 1
}
override func viewWillAppear(animated: Bool) {
self.tableView.tableFooterView = UIView(frame: CGRect.zeroRect)
/// OR
self.tableView.tableFooterView = UIView()
}
사용 UITableViewController
허용 된 솔루션은의 높이를 변경합니다 TableViewCell. 이를 해결하려면 다음 단계를 수행하십시오.
ViewDidLoad방법으로 아래에 주어진 코드 스 니펫을 작성하십시오 .tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];TableViewClass.m파일에 다음 방법을 추가 하십시오.- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return (cell height set on storyboard); }
그게 다야. 프로젝트를 빌드하고 실행할 수 있습니다.
아래 방법에서 :
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (([array count]*65) > [UIScreen mainScreen].bounds.size.height - 66)
{
Table.frame = CGRectMake(0, 66, self.view.frame.size.width, [array count]*65));
}
else
{
Table.frame = CGRectMake(0, 66, self.view.frame.size.width, [UIScreen mainScreen].bounds.size.height - 66);
}
return [array count];
}
여기서 65는 셀의 높이이고 66은 UIViewController의 탐색 막대의 높이입니다.
참고 URL : https://stackoverflow.com/questions/14520185/how-to-remove-empty-cells-in-uitableview
'development' 카테고리의 다른 글
| JavaScript Date 객체에 시간을 추가 하시겠습니까? (0) | 2020.03.02 |
|---|---|
| Android에서 예 / 아니요 대화 상자를 표시하는 방법은 무엇입니까? (0) | 2020.03.02 |
| 선행 및 후행 공백을 자르는 방법? (0) | 2020.03.02 |
| 일반 방법을 숫자 유형으로 제한하는 제약 조건이 있습니까? (0) | 2020.03.02 |
| 복사 제거 및 반환 값 최적화 란 무엇입니까? (0) | 2020.03.02 |