2016-10-23 2 views
0

큰 텍스트 레이블과 2 개의 작은 텍스트 레이블이 필요한 기능이 있습니다. 이 함수는 데이터베이스에서 데이터를 가져와 반복적으로 내 3 개의 텍스트 레이블에 넣습니다. 그러나 내 기본 textlabel 만 표시됩니다. 두 detailTextLabels는 표시되지 않습니다.detailTextLabel이 표시되지 않습니다

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    // Retrieve cell 
    let cellIdentifier: String = "BasicCell" 
    let myCell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier)! 
    // Get the location to be shown 
    let item: Parsexml = feedItems[indexPath.row] as! Parsexml 
    // Get references to labels of cell 
    print(item) 
    myCell.textLabel!.text = item.name! + " | " + item.address! + " " + item.nr! 
    myCell.detailTextLabel?.text = "City: " + item.city! 
    myCell.detailTextLabel?.text = "category: " + item.category! 
    //Label styling 
    myCell.textLabel?.textColor = UIColor(white: 1, alpha: 1) 
    myCell.textLabel?.font = UIFont(name: "HelveticaNeue-Bold", size: 12) 
    return myCell 
} 

스위프트 3에 내 세부 텍스트 레이블을 표시하려면 어떻게해야합니까?

+0

어쩌면 당신은 당신의 셀에'.addSubview'를 잊었을까요? –

+0

셀이 사용자 정의 셀인 것처럼 보이기 때문에이 셀을 참조하는 커스텀 클래스를 생성해야합니다 ('UITableViewCell' of-course를 하위 클래스 화하여). 그런 다음 해당 클래스를 사용하여 사용자 정의 셀에 액세스하십시오. – rptwsthi

답변

0

즉, 3 개의 UILables가있는 사용자 정의 셀이 있습니까? 때문에이 라인이

let myCell: YouCustomCell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier)! 

같아야 경우에 당신은

myCell.1stLable.text = item.name! + " | " + item.address! + " " + item.nr! 
myCell.2ndLable.text = "City: " + item.city! 
myCell.3rdLable.text = "category: " + item.category! 

당신은 스토리 보드의 셀 식별자를 설정해야 사용할 수 있습니다.

+0

나는 그것을 얻지 않는다. 내 스토리 보드 식별자는 "BasicCell"이라고합니다. - 스타일이 맞춤 설정되어 있습니까? 그럼 정확히 무엇입니까? 적어도이 안에 detailTextLabel을 넣을 수 있어야합니까? –

+0

UITableViewCell의 하위 클래스를 만들고 UILables를 해당 클래스로 드래그하여 콘센트를 만들어야합니다. – Sofeda

+0

콘텐츠가 반복 될 때 어떻게 할 수 있나요 ?? –

관련 문제