1
내가 만든 사용자 정의 셀에 UITableView에있는 데이터를 표시하려고합니다. 이건 내 사용자 정의 셀 클래스 (CustomCell.m)입니다 : 다음UITable에 사용자 정의 셀 표시
@implementation CustomCell
@synthesize primaryLabel, secondaryLabel, myImageView;
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
if (self == [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
// Initialization code
primaryLabel = [[UILabel alloc]init];
primaryLabel.textAlignment = UITextAlignmentLeft;
primaryLabel.font = [UIFont systemFontOfSize:14];
secondaryLabel = [[UILabel alloc]init];
secondaryLabel.textAlignment = UITextAlignmentLeft;
secondaryLabel.font = [UIFont systemFontOfSize:8];
myImageView = [[UIImageView alloc]init];
[self.contentView addSubview:primaryLabel];
[self.contentView addSubview:secondaryLabel];
[self.contentView addSubview:myImageView];
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
CGRect contentRect = self.contentView.bounds;
CGFloat boundsX = contentRect.origin.x;
CGRect frame;
frame= CGRectMake(boundsX+10 ,0, 50, 50);
myImageView.frame = frame;
frame= CGRectMake(boundsX+70 ,5, 200, 25);
primaryLabel.frame = frame;
frame= CGRectMake(boundsX+70 ,30, 100, 15);
secondaryLabel.frame = frame;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
}
, 나는 사용자 정의 세포가 표시되어야하는있는 tableView (TeamsViewController.m)을 가지는 rootViewController을 만들어 :
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return 5;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Custom cell here
switch (indexPath.row) {
case 0:
cell.primaryLabel.text [email protected]"Meeting on iPhone Development";
cell.secondaryLabel.text = @"Sat 10:30";
cell.myImageView.image = [UIImage imageNamed:@"Icon4.png"];
break;
case 1:
cell.primaryLabel.text = @"Call With Client";
cell.secondaryLabel.text = @"Planned";
cell.myImageView.image = [UIImage imageNamed:@"Icon4.png.png"];
break;
case 2:
cell.primaryLabel.text = @"Appointment with Joey";
cell.secondaryLabel.text = @"2 Hours";
cell.myImageView.image = [UIImage imageNamed:@"Icon4.png.png"];
break;
case 3:
cell.primaryLabel.text = @"Call With Client";
cell.secondaryLabel.text = @"Planned";
cell.myImageView.image = [UIImage imageNamed:@"Icon4.png.png"];
break;
case 4:
cell.primaryLabel.text = @"Appointment with Joey";
cell.secondaryLabel.text = @"2 Hours";
cell.myImageView.image = [UIImage imageNamed:@"Icon4.png.png"];
break;
default:
break;
}
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 50;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
[self.navigationController pushViewController:self.teamsView animated:YES];
}
그래서, 문제는 : 데이터가 세포에 표시되지 않는 이유를 이해하지 못합니다. 다음은 현재 보이는 모습의 스크린 샷입니다.
http://dl.dropbox.com/u/1481176/Screen%20shot%202010-12-16%20at%203.30.42%20PM.png
어떤 도움을 크게 감상 할 수있다! 감사. 당신은 대신 initWithStyle:reuseIdentifier:
를 호출
이 선을 의미합니까 : 세포 = [[[CustomCell의 ALLOC] initWithStyle : UITableViewCellStyleDefault reuseIdentifier : CellIdentifier] 오토 릴리즈] }? 그렇다면 내가 무엇을 바꾸어야하는지, 왜 그런지, 나는 분명히 논리를 얻지 못한다. – SalsaSalsa
또한, 메모에서 강조 표시된 코드 블록에 어떻게 선을 만듭니 까? – SalsaSalsa
아, 내 마음이 잘못 됐다는 것을 알지 못한다. 작은 오타되었습니다 :(여전히 코멘트에 코드를 만드는 방법에 관심이 많습니다 :) – SalsaSalsa