2014-12-21 2 views
2

나는 Tableview 셀을 가지고 있으며 그 안에는 ImageViewLabel이 있습니다. 하지만 사용하여 연결할 때 :Swift에서 UITableViewCell 레이블 연결

@IBOutlet weak var menuListLabel: UILabel! 
@IBOutlet weak var menuListImage: UIImageView! 

enter image description here

불법 구성 :

있는 UIImageView에의 ViewController에서 menuListImage 콘센트가 잘못 입니다. 콘센트는 반복되는 콘텐트에 연결할 수 없습니다.

답변

5

UITableViewCell에서 상속하는 사용자 지정 클래스를 만들고 거기에 콘센트를 구성해야합니다.

class MyCustomTableViewCell: UITableViewCell { 
    @IBOutlet weak var menuListLabel: UILabel! 
    @IBOutlet weak var menuListImage: UIImageView! 
} 

다음으로 스토리 보드에 셀을 구성해야합니다. 셀을 선택하십시오. ID 관리자를 열고 사용자 정의 클래스를 "MyCustomTableViewCell"로 설정하십시오.

그런 다음 셀을 계속 선택하고 속성 관리자로 이동하여 재사용 식별자를 "MyCustomTableViewCell"로 설정하십시오. (이 식별자는 원하는 것일 수 있습니다. 'dequeueReusableCellWithIdentifier'를 호출 할 때이 정확한 값을 사용해야합니다. 셀의 클래스 이름을 식별자로 사용하여 기억하기 쉽습니다.)

테이블 뷰 컨트롤러 사용자 정의 셀을 사용하여 테이블을 빌드하는 데 필요한 메소드를 구현하십시오.

func numberOfSectionsInTableView(tableView: UITableView) -> Int { 

    return 1 // however many sections you need 
} 

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 

    return 1 // however many rows you need 
} 

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

    // get an instance of your cell 
    let cell = tableView.dequeueReusableCellWithIdentifier("MyCustomTableViewCell", forIndexPath: indexPath) as MyCustomTableViewCell 

    // populate the data in your cell as desired 
    cell.menuListLabel.text = "some text" 
    cell.menuListImage.image = UIImage(named: "some image") 

    return cell 
} 
관련 문제