UITableView에 바닥 글을 추가하는 방법은 무엇입니까?
이 코드를 사용하여 TableView에 바닥 글을 추가합니다. 여기에는 20 개의 섹션이 있으며 각 섹션에는 몇 개의 행이 있습니다. titleForHeaderInSection 및 sectionForSectionIndexTitle 메서드가 있습니다.
CGRect footerRect = CGRectMake(0, 0, 320, 40);
UILabel *tableFooter = [[UILabel alloc] initWithFrame:footerRect];
tableFooter.textColor = [UIColor blueColor];
tableFooter.backgroundColor = [self.theTable backgroundColor];
tableFooter.opaque = YES;
tableFooter.font = [UIFont boldSystemFontOfSize:15];
tableFooter.text = @"test";
self.theTable.tableFooterView = tableFooter;
[tableFooter release];
내가 도대체 뭘 잘못하고있는 겁니까?
감사,
RL
특히 내 코드에서
self.theTable.tableFooterView = tableFooter;
작품과
[self.theTable.tableFooterView addSubview:tableFooter];
작동하지 않습니다. 따라서 전자를 고수하고 다른 곳에서 가능한 버그를 찾으십시오. HTH
UITableViewDelegate 메서드를 구현해야합니다.
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
테이블의 해당 섹션에 대해 원하는 뷰 (예 : 바닥 글에 원하는 텍스트가있는 UILabel)를 반환합니다.
나는 그것을 사용했고 완벽하게 작동했습니다. :)
UIView* footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)];
[footerView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"ProductCellBackground.png"]]];
self.tableView.tableFooterView = footerView;
[self.tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
[self.tableView setContentInset:(UIEdgeInsetsMake(0, 0, -500, 0))];
나는 이것이 꽤 오래된 질문이라는 것을 알고 있지만 방금 같은 문제를 만났습니다. 정확히 이유는 모르겠지만 tableFooterView는 UIView의 인스턴스 일 수있는 것 같습니다 ( "종류"가 아니라 "멤버") ... 그래서 제 경우에는 새 UIView 개체 (예 : wrapperView)를 만들었습니다. 내 사용자 지정 하위보기를 추가하십시오 ... 귀하의 경우에는 다음에서 코드를 chamge하십시오.
CGRect footerRect = CGRectMake(0, 0, 320, 40);
UILabel *tableFooter = [[UILabel alloc] initWithFrame:footerRect];
tableFooter.textColor = [UIColor blueColor];
tableFooter.backgroundColor = [self.theTable backgroundColor];
tableFooter.opaque = YES;
tableFooter.font = [UIFont boldSystemFontOfSize:15];
tableFooter.text = @"test";
self.theTable.tableFooterView = tableFooter;
[tableFooter release];
에:
CGRect footerRect = CGRectMake(0, 0, 320, 40);
UIView *wrapperView = [[UIView alloc] initWithFrame:footerRect];
UILabel *tableFooter = [[UILabel alloc] initWithFrame:footerRect];
tableFooter.textColor = [UIColor blueColor];
tableFooter.backgroundColor = [self.theTable backgroundColor];
tableFooter.opaque = YES;
tableFooter.font = [UIFont boldSystemFontOfSize:15];
tableFooter.text = @"test";
[wrapperView addSubview:tableFooter];
self.theTable.tableFooterView = wrapperView;
[wrapperView release];
[tableFooter release];
도움이 되었기를 바랍니다. 그것은 나를 위해 작동합니다.
처음에는 방법을 시도했습니다.
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
그러나 이것을 다음과 함께 사용한 후 :
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
문제가 해결되었습니다. 샘플 프로그램
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 30.0f;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *sampleView = [[UIView alloc] init];
sampleView.frame = CGRectMake(SCREEN_WIDTH/2, 5, 60, 4);
sampleView.backgroundColor = [UIColor blackColor];
return sampleView;
}
UITableViewDelegate 프로토콜을 포함합니다.
@interface TestViewController : UIViewController <UITableViewDelegate>
이 샘플은 잘 작동합니다. 섹션을 확인한 다음 높이를 반환하여 섹션을 표시하거나 숨길 수 있습니다. 에서 뷰 컨트롤러를 확장하는 것을 잊지 마십시오 UITableViewDelegate
.
목표 -C
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
if (section == 0)
{
// to hide footer for section 0
return 0.0;
}
else
{
// show footer for every section except section 0
return HEIGHT_YOU_WANT;
}
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *footerView = [[UIView alloc] init];
footerView.backgroundColor = [UIColor blackColor];
return footerView;
}
빠른
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let footerView = UIView()
footerView.backgroundColor = UIColor.black
return footerView
}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
if section == 0 {
// to hide footer for section 0
return 0.0
} else {
// show footer for every section except section 0
return HEIGHT_YOU_WANT
}
}
아래 Swift 2.1.1 이 작동합니다.
func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let v = UIView()
v.backgroundColor = UIColor.RGB(53, 60, 62)
return v
}
func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 80
}
If use self.theTable.tableFooterView = tableFooter
there is a space between last row and tableFooterView
.
[self.tableView setTableFooterView:footerView];
instead of
self.theTable.tableFooterView = tableFooter;
try
[self.theTable.tableFooterView addSubview:tableFooter];
I had the same problem but I replaced the following line in my header:
@interface MyController : UIViewTableViewController <UITableViewDelegate, UITableViewDataSource>
with this line and it works as expected:
@interface RequestViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
Notice the UIViewController. Good luck :)
If you don't prefer the sticky bottom effect i would put it in viewDidLoad()
https://stackoverflow.com/a/38176479/4127670
ReferenceURL : https://stackoverflow.com/questions/5144835/how-to-add-a-footer-to-the-uitableview
'IT TIP' 카테고리의 다른 글
바이트는 다르지만 값은 같은 유니 코드 문자열을 어떻게 비교합니까? (0) | 2020.12.29 |
---|---|
viewstate를 디코딩하는 방법 (0) | 2020.12.29 |
git이 cygwin에서 파일을 실행 불가능하게 만드는 것을 막는 방법은 무엇입니까? (0) | 2020.12.29 |
PHP SoapClient에서 인증서 확인 비활성화 (0) | 2020.12.29 |
지원 저항 알고리즘-기술 분석 (0) | 2020.12.29 |