我用UITableView得到了應用程序。重新加載動態表中的TableViewCell的UILabels
每個UITableViewCell中都有UILabel。我以這種方式添加標籤:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//look at the upd
}
但是,當我嘗試在此表以及其他一些信息,老infromation(舊標籤)重新加載數據不消失,但仍對細胞。
它看起來像這樣:...
我應該怎麼有組織加入UILabels?
UPD
我這樣正確的代碼:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Recent Dream";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
UILabel *textLabel = [[UILabel alloc] init];
textLabel.frame = CGRectMake(10, 0, self.view.frame.size.width -110, 48);
textLabel.backgroundColor = [UIColor clearColor];
textLabel.font = [UIFont boldSystemFontOfSize:16];
[textLabel setTag:(int)indexPath];
[cell.contentView addSubview:textLabel];
}
// Configure the cell...
Dream *tempDream = [self.dreams objectAtIndex:indexPath.row];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MM/dd/yyyy"];
//Optionally for time zone converstions
[formatter setTimeZone:[NSTimeZone timeZoneWithName:@"..."]];
NSString *stringFromDate = [formatter stringFromDate:tempDream.dateAdd];
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"bodyWrapper.png"]];
cell.contentView.backgroundColor = background;
UILabel *textLabel = (UILabel *)[cell viewWithTag:(int)indexPath];
textLabel.text = tempDream.title;
NSLog(@"%@",tempDream.title);
NSLog(@"%@",textLabel.text);
cell.textLabel.text = @"";
cell.detailTextLabel.text = stringFromDate;
return cell;
}
和輸出是這樣的:
2012-02-20 15:58:10.512 DreamerIOS[3037:10403] lllooooonggg dreeeeeeeaaaaammmm yeeeeeeah
2012-02-20 15:58:10.513 DreamerIOS[3037:10403] (null)
2012-02-20 15:58:10.516 DreamerIOS[3037:10403] dream to end
2012-02-20 15:58:10.516 DreamerIOS[3037:10403] (null)
2012-02-20 15:58:10.519 DreamerIOS[3037:10403] adsfhadskgh dfagfadkuy gadyv dsfdfad fsdf a ghfncdhg hjfg f dfj ghf
2012-02-20 15:58:10.519 DreamerIOS[3037:10403] (null)
所以的NSLog(@ 「%@」,tempDream.title) ;是好的,但NSLog(@「%@」,textLabel.text);一片空白。爲什麼?
看看UPD請 – 2012-02-20 10:04:41
更新,對不起我的英文不好 – Hanon 2012-02-20 10:19:18
[爲textLabel setTag:1];和UILabel * textLabel =(UILabel *)[cell viewWithTag:1];但仍null =( – 2012-02-20 10:50:16