我發現了一些類似於我的問題但不完全相同的帖子。在uitableviewcell上tableview中的重複行
在我的應用程序中,用戶可以在幾個可用視圖之間導航,以深入到所需的結果。當用戶前進時,然後向後,然後向前等,顯而易見的是行被重繪/重寫,並且文本變得更大膽和更大膽。
我發現在某些帖子中,這可能與我創建行的方式有關,使用cellforrowatindexpath
方法中的uilable。
是否有我需要做的事情,以防止每次用戶在桌面視圖之間前後移動時重新填充/重繪行?我是否需要在下面的代碼中添加一些東西或者添加一些東西到viewwillappear方法中(目前在桌面上有一個'reloaddata',但似乎沒有幫助)?
這裏是我的代碼:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
UILabel *label = [[[UILabel alloc] init] autorelease];
label.font = [UIFont fontWithName:@"Arial-BoldMT" size:20];
label.frame = CGRectMake(10.0f, 10.0f, 220.0f, 22.0f);
label.textColor = [UIColor blackColor];
label.backgroundColor = [UIColor clearColor];
label.opaque = NO;
label.text = [mapareaArray objectAtIndex:indexPath.row];
[cell.contentView addSubview:label];
CustomCellBackgroundView *bgView = [[CustomCellBackgroundView alloc] initWithFrame:CGRectZero];
bgView.borderColor = [UIColor clearColor];
bgView.fillColor = [UIColor whiteColor];
bgView.position = CustomCellBackgroundViewPositionSingle;
cell.backgroundView = bgView;
return cell;
}
非常感謝你。大的幫助。 關於此問題的最後一個問題 - 我沒有編程背景,所以不知道在頭文件中使用#define是什麼意思。這是什麼語法?我以前看過它,並試圖在標題中放置'#define kMyTag',但這不起作用...我假設你需要將kMyTag定義爲一個值,但不確定這樣做的語法是什麼。你能幫我嗎? – SKayser 2009-08-25 11:49:24