gpt4 book ai didi

iphone - TableView 单元格模糊

转载 作者:搜寻专家 更新时间:2023-10-30 20:22:14 26 4
gpt4 key购买 nike

我在查看表格 View 中的单元格时遇到了一个有趣的问题: 起初,当加载 tableview 时,单元格看起来有点模糊,奇怪的是,当显示然后隐藏键盘时,它们将被固定,直到再次滑动表格(出列新单元格)。 Before

After

一般来说,tableview 中有 3 种类型的单元格(CustomCellWithButton、AddSlidesCells 和 CustomCell)。模糊可以在所有这些中找到,但在 CustomCell 中可以清楚地看到。这让我抓狂 :S 请帮忙

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier;
if((indexPath.section == 4 && (indexPath.row == 1)))
{
CellIdentifier = @"CustomCellWithButton";
CustomCellWithButton *cell = (CustomCellWithButton*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCellWithButton" owner:nil options:nil];

for(id currentObject in topLevelObjects){
if([currentObject isKindOfClass:[UITableViewCell class]]){
cell = (CustomCellWithButton *)currentObject;
break;
}
}
}
[cell.button addTarget:self action:@selector(nextButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
[cell setBackgroundColor:[UIColor darkGrayColor]];

return cell;
}
else
{
if((indexPath.section == 3 && (indexPath.row == 0))){
CellIdentifier = @"AddSlidesCells";

AddSlidesCells *cell = (AddSlidesCells*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"AddSlidesCells" owner:nil options:nil];

for(id currentObject in topLevelObjects){
if([currentObject isKindOfClass:[UITableViewCell class]]){
cell = (AddSlidesCells *)currentObject;
break;
}
}
}

[cell.switchButton setOn:[self getswitchButtonsStatesByIndexPath:indexPath] withIndexpath:indexPath];
[cell.switchButton addTarget:self action:@selector(switchChanged:forEvent:)
forControlEvents:(UIControlEventValueChanged | UIControlEventTouchDragInside)];
[cell.button addTarget:self action:@selector(addSlicePressed:) forControlEvents:UIControlEventTouchDown];

NSLog(@" ---- here add to dismiss keyboared");

[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
[cell setBackgroundColor:[UIColor darkGrayColor]];

if (alignedLeft) {
[cell hardAllignToLeft];

}else
[cell hardAllignToRight];

return cell;
}

else
{
CellIdentifier = @"CustomCell";
BOOL dequed;
CustomCell *cell = (CustomCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSString* placeHolder = [self getplaceHoldersByIndexPath:indexPath];

if (cell == nil) {
dequed = NO;
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:nil options:nil];

for(id currentObject in topLevelObjects){
if([currentObject isKindOfClass:[UITableViewCell class]]){
cell = (CustomCell *)currentObject;
[cell setFrame:CGRectMake(0, 0, 320, 50)];

break;
}
}
}else
dequed = YES;

cell.alignedLeft = alignedLeft;

[cell.textField setPlaceholder:placeHolder];
[cell.textField setText:[self getTextfieldByIndexPath:indexPath] andIndexPath:indexPath];
[cell.switchButton setOn:[self getswitchButtonsStatesByIndexPath:indexPath] withIndexpath:indexPath];
[cell.switchButton addTarget:self action:@selector(switchChanged:forEvent:)
forControlEvents:(UIControlEventValueChanged | UIControlEventTouchDragInside)];
[cell.textField addTarget:self action:@selector(UIControlEventEditingChanged:)
forControlEvents:UIControlEventEditingChanged];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
cell.textField.delegate = self;

if( [placeHolder isEqualToString:[OperationsOnCoreData PlistCommonStrings:@"Telephone"]] ||
[placeHolder isEqualToString:[OperationsOnCoreData PlistCommonStrings:@"Email"]]){

cell.plusSignButton.hidden = NO;
cell.minusSignButton.hidden = YES;
[cell.plusSignButton addTarget:self action:@selector(plusSignButtonPressed:)
forControlEvents:UIControlEventTouchUpInside];
}
else
if(( !([placeHolder rangeOfString:[NSString stringWithFormat:@"%@ ",[OperationsOnCoreData PlistCommonStrings:@"Telephone"]]].location == NSNotFound)||
!([placeHolder rangeOfString:[NSString stringWithFormat:@"%@ ",[OperationsOnCoreData PlistCommonStrings:@"Email"]]].location == NSNotFound))){

cell.minusSignButton.hidden = NO;
cell.plusSignButton.hidden = YES;
[cell.minusSignButton addTarget:self action:@selector(minusSignButtonPressed:)
forControlEvents:UIControlEventTouchUpInside];
}
else{
cell.minusSignButton.hidden = YES;
cell.plusSignButton.hidden = YES;
}


if(cell.switchButton.on){
[cell.textField setEnabled:YES];
cell.textField.alpha = 1;
}else{
[cell.textField setEnabled:NO];
cell.textField.alpha = 0.5;
cell.plusSignButton.enabled = NO;
cell.minusSignButton.enabled = NO;
}

[cell setBackgroundColor:[UIColor darkGrayColor]];

if (alignedLeft) {
[cell hardAllignToLeft];

}else
[cell hardAllignToRight];
return cell;
}
}

最佳答案

模糊单元格看起来很模糊,因为元素比非模糊单元格低一个像素。所以模糊的外观是由调整开关按钮和加号图标的大小引起的。

要修复它,您需要调查单元格的布局,尤其是这些元素的大小。他们可能应该始终保持自然大小。粘贴的代码不包含相关部分。

关于iphone - TableView 单元格模糊,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7460120/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com