나는이 작업을 수행 할 수 있지만 작동해야한다고 생각하는 방법이 왜 작동하지 않는지 궁금합니다. 나는 uitableviewcell을 가진 .xib와 클래스로서 WirelessCell.h/.m을 가지고있다. ADVPercentProgressBar라는 개체를 셀에 추가하려고합니다.사용자 지정 재사용 가능한 셀에 개체 추가
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
int section = indexPath.section;
int row = indexPath.row;
if (section == 6) {
// Make dynamic rows cell
static NSString *CellIdentifier = @"wireless3";
WirelessCell *cell = (WirelessCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"WirelessCell" owner:nil options:nil];
cell = [topLevelObjects objectAtIndex:0];
cell.progressBar = [[ADVPercentProgressBar alloc] initWithFrame:CGRectMake(10, 22, 300, 28) andProgressBarColor:ADVProgressBarBlue];
[cell addSubview:cell.progressBar];
}
// Set labels here
NSDictionary *tmpDict = [[[DataSingleton sharedSingleton] sharedWirelessClients] objectAtIndex:row];
cell.labelUptime.text = [tmpDict objectForKey:@"uptime"];
[cell.progressBar setProgress:[[tmpDict objectForKey:@"signal"] intValue]*0.001];
return cell;
} else {
return [super tableView:tableView cellForRowAtIndexPath:indexPath];
}
}
이 셀 초기화 중에 ADVPercentProgressBar를 추가 잘 작동하지만 내가 세포에 ADVPercentProgressBar을 넣을 수 있다고 생각이 같은 initWithStyle :
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
progressBar = [[ADVPercentProgressBar alloc] initWithFrame:CGRectMake(10, 22, 300, 28) andProgressBarColor:ADVProgressBarBlue];
[self.contentView addSubview:progressBar];
}
및하지의 내 cellForRowAtIndexPath은 다음과 같습니다 ViewController 셀 초기화 그러나 이것은 효과가 없습니다. 왜 나는 셀 클래스 초기화에 객체를 추가하는 것이 논리적 인 것처럼 보이는지 궁금합니다. return self; }
귀하의 권리는 awakeFromNib을 사용하여 작동합니다. 그러나 위의 코드 (그리고 내가 지금 awakeFromNib와 함께 사용하고있는 것)는 * 셀이 dequereusable 셀이 아닌 셀이 되는가? 이 점이 중요합니까? – Darren
식별자가 일치하면 큐에서 제거 할 수 있습니다. 세포가 어디서 왔는지는 중요하지 않습니다. –