我对UICollectionViewCells有一个令人沮丧的问题。我在这个应用程序中使用默认流程。这是问题所在:
初次加载时,“已关闭”标签会在单元格中正确显示。我们通过下拉或转到另一个页面并返回来重新加载CollectionView,“Closed”标签仅显示在第一个单元格上。
“封闭”标签已在IB中添加并命名。我尝试使用标签名称以及标记标签并使用标签参考。
当我调试代码时,它会通过正确的“封闭”标签流程。 “已关闭”标签是实例,不是零。在代码中看来,一切都应该是快乐和好的,但显示它不是。
以下是数据初始加载的屏幕截图:
以下是重新加载的屏幕截图:
现在代码 - 这里是cellForItemAtIndexPath
函数:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
NSMutableString *topMiddle = [NSMutableString new];
NSMutableString *bottomMiddle = [NSMutableString new];
NSMutableString *bottom = [NSMutableString new];
Tab *theTab = [self.fetchedResultsController objectAtIndexPath:indexPath];
// figure out the date this started
[bottomMiddle appendString:@"Start: "];
[bottomMiddle appendString:[_dateFormatted stringFromDate:[theTab startdate]]];
// figure out the due date/closed date stuff
if ([theTab closeddate] != nil) {
[bottom appendString:@"Closed: "];
[bottom appendString:[_dateFormatted stringFromDate:[theTab closeddate]]];
} else if ([theTab duedate] == nil) {
[bottom appendString:@"No Due Date"];
} else if ([theTab duedate] != nil){
[bottom appendString:@"Due: "];
[bottom appendString:[_dateFormatted stringFromDate:[theTab duedate]]];
}
long duedaterange = [self numberOfDaysTillDueDate:[theTab duedate]];
CreditorCollectionViewCell *cellC;
if ([[theTab debitor] intValue] == 0) {
cellC = [collectionView dequeueReusableCellWithReuseIdentifier:reuseCreditorIdentifier forIndexPath:indexPath];
[cellC.topLabel setText:[theTab name]];
[topMiddle appendString:@"They Owe: "];
[topMiddle appendString:@"\n"];
[topMiddle appendString:[_currencyFormatted stringFromNumber:[theTab amountcurrent]]];
[cellC.topMiddleLabel setText:topMiddle];
[cellC.bottomMiddleLabel setText:bottomMiddle];
[cellC.bottomLabel setText:bottom];
[cellC setTheTab:theTab];
// set this as hidden unless it is closed
if ([theTab closeddate] == nil) {
[[cellC viewWithTag:102] setHidden:YES];
} else {
[[cellC viewWithTag:102] setHidden:NO];
}
if ([theTab closeddate] != nil) {
// the tab is CLOSED
[cellC setBackgroundColor:[UIColor lightGrayColor]];
[[cellC viewWithTag:102] setCenter:cellC.center];
[[cellC viewWithTag:102] setBackgroundColor:[UIColor clearColor]];
[(UILabel *)[cellC viewWithTag:102] setTextColor:[UIColor darkGrayColor]];
CGAffineTransform tcheck = [cellC viewWithTag:102].transform;
// make sure the transform has not been applied already
if ((tcheck.a == 0 || tcheck.a == 1) && (tcheck.b == 0 || tcheck.b == 1) &&
(tcheck.c == 0 || tcheck.c == 1) && (tcheck.d == 0 || tcheck.d == 1)) {
// turn the closed sign
float angleDim = (cellC.bounds.size.height/cellC.bounds.size.width);
float angle = atanf(angleDim);
// apply the trnasformation to angle the closed label
CGAffineTransform transform = CGAffineTransformRotate([cellC viewWithTag:102].transform, -angle);
[cellC viewWithTag:102].transform = transform;
}
} else if ((duedaterange == 0) && ([bottom containsString:@"No Due Date"])) {
// either day of or none set
[cellC setBackgroundColor:[UIColor greenColor]];
} else if (duedaterange >= 10) {
// more than 10 days out (green)
[cellC setBackgroundColor:[UIColor greenColor]];
} else if (duedaterange < 0) {
// PAST DUE (red)
[cellC setBackgroundColor:[UIColor redColor]];
} else {
// coming close (yellow)
[cellC setBackgroundColor:[UIColor yellowColor]];
}
return cellC;
}
return nil;
}
有什么想法吗?