사용자 정의 UITableViewCell을 사용하여 iOS 어플리케이션에서 UITableView에 결과를 표시하려고합니다. 셀의 textLabel 및 detailTextLabel 속성을 사용하면 내 Array의 내용을 볼 수 있지만 UITableView를 사용자 정의 셀 클래스와 연결하여 Array의 내용을 표시하려고하면 인터페이스의 기본값 만 가져옵니다. 내 테이블에 표시 빌더입니다.iOS에서 사용자 정의 UITableViewCell을 볼 수 없습니다.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
CustomTableCell *cell = (CustomTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[CustomTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
TransactionList *tList = [_list objectAtIndex:indexPath.row];
/*
cell.transaction.text = tList.transaction;
cell.type.text = tList.type;
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"ddMMYYYY"];
NSString *dateAsString = [formatter stringFromDate:tList.date];
cell.date.text = dateAsString;
*/
//this code below displays the contents just fine, but the block of code above does not.
cell.textLabel.text = tList.transaction;
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@, %@", tList.type, tList.status];
return cell;
}
아래의 방법은 내 CustomTableCell 클래스에있는 것입니다 :
이 내가 가진 관련 코드는
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.contentView.frame = CGRectMake(0, 0, 320, 80);
_transaction = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 80, 40)];
[_transaction setBackgroundColor:[UIColor clearColor]];
[_transaction setFont:[UIFont systemFontOfSize:12]];
[_transaction setNumberOfLines:2];
[_transaction setLineBreakMode:NO];
[self.contentView addSubview:_transaction];
_date = [[UILabel alloc] initWithFrame:CGRectMake(100, 5, 80, 40)];
[_date setBackgroundColor:[UIColor clearColor]];
[_date setFont:[UIFont systemFontOfSize:12]];
[_date setNumberOfLines:2];
[_date setLineBreakMode:NO];
[self.contentView addSubview:_date];
_type = [[UILabel alloc] initWithFrame:CGRectMake(200, 5, 80, 40)];
[_type setBackgroundColor:[UIColor clearColor]];
[_type setFont:[UIFont systemFontOfSize:12]];
[_type setNumberOfLines:2];
[_type setLineBreakMode:NO];
_type.lineBreakMode = NO;
[self.contentView addSubview:_type];
}
return self;
}
경우 _transaction, _date 및 _type 레이블입니다. 여기 MainStoryboard 안에 내 인터페이스 빌더의 스크린 샷이다 : 나는 "기본"에서 스타일을 변경 시도
에 "사용자 정의"에 "자막"하지만 도움이되지 않습니다. 테이블의 기본값 만 표시하며 이러한 설정은 표 시되는 방식으로 바뀌지 만 내 Array의 내용이 표에 나타나지 않습니다. 누구든지 내가 뭘 잘못하고 있는지 볼 수 있니? 나는 정말로 그 문제가 단순한 것이라고 생각하지만, 불행하게도 나는 그것에 손가락을 대지 않을 수있다.
미리 답변 해 주신 모든 분께 감사드립니다.
정말 감사합니다. 어떻게 그리고 어디서부터 내 물건에 "떨어 뜨릴"것입니까? 트랜잭션, 날짜 및 유형은 단순히 레이블이며 .h 파일에서 선언되지만 IB의 CustomTableCell에는 연결되지 않습니다. 나는 그들이 있어야 할 것 같아요? – syedfa
선언되었으므로 좋습니다. 이제 오브젝트 라이브러리에서 오브젝트 (예 : 2 UILabels, Master & Value)를 삭제하십시오. 그런 다음 컨트롤을 드래그하여 CustomTableCell에 연결할 수 있습니다. 귀하의 경우 @property 정의 왼쪽의 원이 비어 있어야합니다. 해당 원에서 CustomTableCell 객체로 드래그합니다. 3 속성이 나타나야합니다. 올바른 것을 선택하십시오. – David