在我的代碼的一部分,我叫不能設置單元格中的α的cellForRowAtIndexPath
UITableViewCell *cell = (UITableViewCell *)[self.tableView cellForRowAtIndexPath:indexPath];
得到一些細胞,然後我改變自己的阿爾法至0.35。這可行,細胞看起來褪色。
但是,當我滾動tableview時,移出窗口然後移回的單元格不再褪色。即使在cellForRowAtIndexPath中,每個禁用的行的alpha值都設置爲.35,但會發生這種情況。
我登錄
NSLog(@"%f", cell.alpha);
,並返回0.35
但是權的cellForRowAtIndexPath返回細胞之前,細胞不滾動後褪色?在顯示之前,它看起來像是阿爾法神奇地變回到1。
以下是我執行的cellForRowAtIndexPath在我科類
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
if ([self disabled])
{
cell = [SectionedTableViewController tableView:tableView dequeueReusableCellWithIdentifier:@"CellDisabled" style:UITableViewCellStyleDefault];
cell.alpha = .35;
}
else
{
cell = [SectionedTableViewController tableView:tableView dequeueReusableCellWithIdentifier:@"CellEnabled" style:UITableViewCellStyleDefault];
cell.alpha = 1;
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
//if-else block that only sets labels is here omitted
if (cell.textLabel.text == [[cs objectAtIndex:[self c]] type])
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
NSLog(@"%f", cell.alpha);
return cell;
}
而且,協調這些部分得到的細胞從他們身上,像這樣的視圖控制器:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"Alpha: %f", [[[self sections] objectAtIndex:indexPath.section] tableView:tableView cellForRowAtIndexPath:indexPath].alpha);
return [[[self sections] objectAtIndex:indexPath.section] tableView:tableView cellForRowAtIndexPath:indexPath];
}
(和NSLog記錄適當的阿爾法值)
您可以發佈您的cellForRowAtIndexPath實現嗎? – Dima