我有一個透明背景顏色的UITableView,它的每個單元都有自定義背景視圖和灰色選擇樣式。選擇工作正常,但是當我選擇並向上或向下拖動桌面視圖時,單元格將其背景更改爲透明而非自定義。我該怎樣修復它?所選的UITableViewCell更改Scroll背景
編輯:源代碼的要求安德烈Morujão
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
RestaurantInfo *restaurantInfo = [requestBean.restaurantArray objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
}
else {
cell = nil;
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
}
[cell setSelectionStyle:UITableViewCellSelectionStyleGray];
UIImageView *bgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
[bgView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"table_cell_bg.png"]]];
[cell setBackgroundView:bgView];
UILabel *restaurantNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 310, 15)];
[restaurantNameLabel setFont:[UIFont boldSystemFontOfSize:16]];
[restaurantNameLabel setText:restaurantInfo.restaurantName];
[restaurantNameLabel setBackgroundColor:[UIColor clearColor]];
[restaurantNameLabel setUserInteractionEnabled:NO];
[cell addSubview:restaurantNameLabel];
return cell;
}
你可以粘貼你的tableView:cellForRowAtIndexPath:? – 2011-05-03 09:11:39
我已經像你說的那樣用方法 – 2011-05-03 09:37:32