development

detailTextLabel이 보이지 않는 이유는 무엇입니까?

big-blog 2021. 1. 9. 11:29
반응형

detailTextLabel이 보이지 않는 이유는 무엇입니까?


detailTextLabel표시되지 않습니다 (아래 코드). 왠지 말해줘?

 // Customize the appearance of table view cells.
 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

// Configure the cell...

NSString *cellValue = [myListArray objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;

cell.detailTextLabel.text = @"Hello "; // This is not visible
cell.image = [myListArrayImages objectAtIndex:indexPath.row];

return cell;
}

detailTextLabel표시되지 않습니다 cellsUITableViewCellStyleDefault스타일. 대신 당신은 당신이 표시되어야합니다 .initUITableViewCellUITableViewCellStyleSubtitledetailTextLabel

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];

또는 Interface Builder를 사용하는 경우 Style셀 속성을 Subtitle. :)

Interface Builder의 스타일 셀 속성.


프로그래밍 방식으로 해결하려면 :

let cell = UITableViewCell(style: .subtitle, reuseIdentifier: "identifier")

UITableViewCell 클래스 참조의 문구가이 문제에 대해 약간 혼란 스러울 수 있음을 언급하고 싶습니다.

(각 세포 유형 설명 후)

" 토론 이러한 모든 셀 스타일에서 더 큰 텍스트 레이블은 textLabel 속성을 통해 액세스하고 더 작은 레이블은 detailTextLabel 속성을 통해 액세스합니다."

모든 셀 유형에 detailTextLabel이 포함되어 있다고 말하는 것처럼 보일 수 있지만 자세히 읽어 보면 detailTextLabel 없는 기본 유형 일뿐입니다.


나는 이것을 사용했고 그것은 나를 위해 일했습니다.

// programming mark ----- ----- ---- ----- ----- ---- ----- ----- ----

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let CellIdentifier: String = "CellIdentifier"

    var cell = tableView.dequeueReusableCellWithIdentifier(CellIdentifier) as? UITableViewCell

    if cell == nil {
        cell = UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: CellIdentifier)
    }

    cell!.textLabel!.text = "Title"
    cell!.detailTextLabel!.text = "Value"

    return cell!
}

참조 URL : https://stackoverflow.com/questions/5190648/why-is-detailtextlabel-not-visible

반응형