4

저는 storyboard 대신 Xib 파일을 사용하고 있습니다. 더미 데이터가있는 테이블 뷰를 만들었습니다. 그것의 잘 작동, 이제 일부 레이블 및 textFields 사용자 지정 셀을 만들었습니다. UITableView의 머리글 또는 바닥 글로 어떻게 사용할 수 있습니까?UITableView의 머리글 또는 바닥 글로 사용자 지정 셀을 설정하는 방법

+0

그것에 대해 당신이 하나의보기 (XIB)을 만들 필요가 당신은 머리글이나 바닥 글로 jQuery과 셀을 사용할 수 없습니다 당신이 그것을 –

+0

셀을 사용할 수 있습니다 헤더로? tableHeaderView는 셀이 아닌 뷰 유형입니다. – ronan

+0

및 Xib를 사용하여 UiView를 만드는 방법은 무엇입니까? 새 코코아 터치 파일을 만들고 UIView의 하위 클래스로 "Xib 파일을 만듭니다"옵션을 사용할 수없는 경우 확인하십시오. – Byte

답변

1

프로그래밍 방식으로 사용자 지정보기를 만들 수 있습니다. 다음 코드를 시도했다. 한 번 해보십시오.

override func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { 
     let customview:UIView = UIView(); 
     let label = UILabel(); 
     label.text = "ur custom data" 
     /* 
      You can add any number of subviews you want here 
      And don't forget to add it to your customview. 
     */ 
     customview.addSubview(label) 
     return customview; 
    } 

마찬가지로 헤더도 똑같이 할 수 있습니다.

1

이것은 TableView의 머리글을 추가하는 방법입니다. 에서 UIButton, UIImageView 등과 같은 모든 컨트롤을 사용할 수 있습니다. 당신은 당신은 헤더의 크기와 바닥 글

func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { 
    return 20.0 
} 

func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { 
    return 20.0 
} 
+0

imageView가 포함 된 cstom보기를 만들었습니다. 내가 간단한보기와 함께이 메서드를 사용하려고하면 nackground 색상이 작동하지만 내 사용자 정의보기와 함께 – Byte

14

대답은 실제로 아주 간단을 추가 할 수 있습니다 제의 바닥 글을 설정할 수 있습니다 위처럼

func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { 
     let sectionView = UIView() 
     sectionView.frame = CGRectMake(x,y,height,width) // For Set the Frame 
     sectionView.backgroundColor = UIColor.redColor() 

     return sectionView 
    } 
func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { 
     let sectionView = UIView() 
     sectionView.frame = CGRectMake(x,y,height,width) // For Set the Frame 
     sectionView.backgroundColor = UIColor.redColor() 

     return sectionView 
    } 

. 에서 cellForRowAtIndexPath()에서와 같이 셀 객체를 생성하고 반환하십시오.

다음은 샘플 코드입니다.

override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { 
    let cell = tableView.dequeueReusableCellWithIdentifier("cellIdentifier") as! YourTableViewCell 
    return cell 
} 

당신은 헤더 높이를 설정할 수 있습니다

override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { 
    return 80 
} 
관련 문제