0
我正在使用以下代碼創建一個帶有標籤的自定義UITableViewCell。當重新使用自定義UITableViewCells內容時
我遇到的問題是,單元格在重用時沒有被清除,而且我不確定如何操作,因爲我不認爲當它出隊時有權訪問單元格內容。
任何人都可以告訴我我該怎麼做嗎?
if (indexPath.section == 2) {
// Resetting the elements in the cell prior to use.
UIView *blankCell;
UILabel *methodText;
static NSString *methodCellIdentifier = @"Method Cell";
methodCell = [tableView dequeueReusableCellWithIdentifier: methodCellIdentifier];
if (methodCell == nil)
{
methodCell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier: methodCellIdentifier] autorelease];
}
blankCell = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
methodText = [[UILabel alloc] initWithFrame:CGRectMake(15, 7, 305, 44)];
methodText.text = [[self.recipeDict objectForKey:@"Method"] objectAtIndex: indexPath.row];
NSLog(@"methodText.text = %@", methodText.text);
[methodText setLineBreakMode:UILineBreakModeWordWrap];
[methodText setNumberOfLines:0];
[methodText sizeToFit];
[blankCell addSubview:methodText];
[methodCell.contentView addSubview:blankCell];
[methodText release];
methodCell.contentMode = UIViewContentModeRedraw;
return methodCell;
}
這工作太好了,謝謝:要訪問這些塊之外,他們創造並使用viewWithTag找到並更新他們的內容時,他們一組標籤值。 –
雖然這在我嘗試後運行良好,但我現在看到類似的問題發生,但我認爲這與我找出由上述代碼生成的單元格的高度有關。你有什麼可以幫忙的嗎? –
雙重檢查,現在它似乎並沒有工作。不知道發生了什麼事。 –