關於刷新自定義表格單元格有許多問題,但這個很奇怪。我有一個tableView,每個單元格現在都有一個自定義的UILabel
和UIImageView
。UITableView自定義單元格不刷新
目前只有2個電池。第一個顯示日期。當表第一次加載時,它將當前日期顯示爲第一個單元格中的字符串UILabel
。
當我選擇所述第一小區,我提出了一種自定義類負責處理所有的時間採摘。一旦挑選了一個日期,這個視圖就會彈出,然後我返回到表格視圖。
在-(void)viewDidAppear
的tableviews數據被重載,新選定的日期應該會出現。
但是,第一個單元格中的標籤未更新。
什麼迷惑的事,如果我有多個小區都顯示相同的數據,這些都將刷新並顯示新的日期,符合市場預期。看起來索引爲0的單元格行不會刷新。
什麼進一步混淆了事情是,當我查詢UILabel
的字符串值單元格,則返回正確的日期。
- (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];
//
// clears the grouped style border from each table cell
//
UIView *clearBgView = [[UIView alloc]initWithFrame:CGRectZero];
[cell setBackgroundView:clearBgView];
// label
UILabel *dl = [[UILabel alloc]initWithFrame:CGRectMake(70.0f, 10.0f, screenWidth-100, 50)];
[self setDetailsLabel:dl];
dl = nil;
[[self detailsLabel] setBackgroundColor:[UIColor colorWithRed:.1 green:.1 blue:.1 alpha:.1 ]];
[[self detailsLabel] setTextColor:[UIColor colorWithRed:1.0f green:1.0f blue:1.0f alpha:.3f]];
//icon for each cell
UIImageView *ci = [[UIImageView alloc]initWithFrame:CGRectMake(10.0f, 10.0f, 50.0f, 50.0f)];
[ci setBackgroundColor:[UIColor colorWithRed:.2 green:.2 blue:.2 alpha:.2]];
[self setCellIcon:ci];
ci = nil;
//
// set up views
//
[cell addSubview:[self cellIcon]];
[cell addSubview:[self detailsLabel]];
}
// Configure the cell...
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
//populate each by row.
NSString *dateDisplay = [self formatDate:[self dateCaught]];
NSLog (@"date is %@", dateDisplay);
[[self detailsLabel] setText:[self formatDate:[self dateCaught]]];
switch (indexPath.row) { //this needs to be an integer, so return the row of the indexPath.
case 0:
NSLog (@"text for the cell is %@",[[self detailsLabel]text]);
break;
default:
break;
}
return cell;
}
感謝您最近的更新,這正是我要做的。我試圖通過像我這樣快速定製單元格內容來嘗試破解它,但正如你所看到的,遇到了問題。 – Tim