表格视图在真实设备上不刷新
Posted
技术标签:
【中文标题】表格视图在真实设备上不刷新【英文标题】:Table view is not refreshing on real device 【发布时间】:2015-05-06 07:07:09 【问题描述】:我的表格视图有问题。
当我选择行时,我的单元格高度正在改变并显示一些信息。如果我第二次选择,它正在关闭。
在模拟器上就像一个魅力,但在真实设备上,第一部分工作正常,但当我想关闭它时,他正在执行代码但可能没有刷新 tableView,因为我的信息保持显示。
真实设备的另一个问题:我的视图没有出现。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
return 1;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
return 4;
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
if (indexPath.row ==1 &&show == YES)
return 50 + descLabel;
else if (indexPath.row == 2 && show2 == YES)
return caracLabel;
return 50;
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
NSString *cellID = @"detailCell";
switch (indexPath.row)
case 0:
cellID = @"detailCell1";
break;
case 1:
cellID = @"detailCell2";
break;
case 2:
cellID = @"detailCell3";
break;
case 3:
cellID = @"detailCell4";
default:
break;
detailCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.label.text = [self.array objectAtIndex:indexPath.row];
cell.image1.image = [UIImage imageNamed:[NSString stringWithFormat:[self.imageArray objectAtIndex:indexPath.row]]];
if (indexPath.row == 1)
if (show == NO)
cell.labelDef.hidden =YES;
return cell;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
if (indexPath.row==1)
if (show == NO )
detailCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"detailCell2" forIndexPath:indexPath];
show=YES;
cell.label.text = [self.array objectAtIndex:indexPath.row];
cell.image1.image = [UIImage imageNamed:[NSString stringWithFormat:[self.imageArray objectAtIndex:indexPath.row]]];
cell.labelDef.text=[self.desc objectAtIndex:pos];
cell.labelDef.sizeToFit;
cell.imageButton.image = [UIImage imageNamed:@"Play_Symbol_copie_5@3x.png"];
cell.labelDef.frame = CGRectMake(10, 50, cell.labelDef.frame.size.width, cell.labelDef.frame.size.height);
cell.labelDef.hidden = NO;
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 50, cell.frame.size.width, cell.labelDef.frame.size.height)];
[view setBackgroundColor:[UIColor whiteColor]];
[cell.contentView addSubview:view];
[cell.contentView addSubview:cell.labelDef];
descLabel = cell.labelDef.frame.size.height ;
// [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]] withRowAnimation:UITableViewRowAnimationMiddle];
[self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]]
withRowAnimation:UITableViewRowAnimationNone];
[self.tableView selectRowAtIndexPath:indexPath
animated:NO
scrollPosition:UITableViewScrollPositionNone];
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
else
detailCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"detailCell2" forIndexPath:indexPath];
show= NO;
cell.label.text = [self.array objectAtIndex:indexPath.row];
cell.image1.image = [UIImage imageNamed:[NSString stringWithFormat:[self.imageArray objectAtIndex:indexPath.row]]];
cell.imageButton.image = [UIImage imageNamed:@"Play_Symbol_copie_2@3x.png"];
cell.labelDef.hidden = YES;
// [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]] withRowAnimation:UITableViewRowAnimationMiddle];
[self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]]
withRowAnimation:UITableViewRowAnimationNone];
[self.tableView selectRowAtIndexPath:indexPath
animated:NO
scrollPosition:UITableViewScrollPositionNone];
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
else if (indexPath.row == 2)
if ( show2 == NO)
detailCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"detailCell3"forIndexPath:indexPath];
show2=YES;
cell.label.text = [self.array objectAtIndex:indexPath.row];
cell.image1.image = [UIImage imageNamed:[NSString stringWithFormat:[self.imageArray objectAtIndex:indexPath.row]]];
cell.imageButton.image = [UIImage imageNamed:@"Play_Symbol_copie_5@3x.png"];
NSArray *firstWords = [[self.carac objectAtIndex:pos] componentsSeparatedByString:@"\n"];
UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 50, cell.frame.size.width , 100)];
[view1 setBackgroundColor:[UIColor colorWithRed:246/256.0 green:245/256.0 blue:241/256.0 alpha:1]];
[cell.contentView addSubview:view1];
caracLabel = 50;
for (int i = 0; i <firstWords.count; i++)
NSArray *array = [[firstWords objectAtIndex:i]componentsSeparatedByString:@"/"];
UILabel *label = [[UILabel alloc]initWithFrame: CGRectMake(10, caracLabel, 90, 20)];
label.text = [array objectAtIndex:0];
label.textColor = [UIColor colorWithRed:150/256.0 green:150/256.0 blue:150/256.0 alpha:1];
label.numberOfLines = 0;
[label sizeToFit];
[cell.contentView addSubview:label];
UILabel *label1 = [[UILabel alloc]initWithFrame: CGRectMake(110, caracLabel, 205, 20)];
label1.text = [array objectAtIndex:1];
label1.textColor = [UIColor colorWithRed:150/256.0 green:150/256.0 blue:150/256.0 alpha:1];
label1.numberOfLines = 0;
[label1 sizeToFit];
caracLabel = caracLabel + label1.frame.size.height;
if (i != firstWords.count - 1)
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, caracLabel, cell.frame.size.width, 1)];
[view setBackgroundColor:[UIColor whiteColor]];
caracLabel =caracLabel+2;
[cell.contentView addSubview:view];
[cell.contentView addSubview:label1];
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(100, 50, 1, caracLabel - 50)];
[view setBackgroundColor:[UIColor whiteColor]];
[cell.contentView addSubview:view];
view1.frame = CGRectMake(0, 50, cell.frame.size.width, caracLabel-50);
// [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]] withRowAnimation:UITableViewRowAnimationMiddle];
[self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]]
withRowAnimation:UITableViewRowAnimationNone];
[self.tableView selectRowAtIndexPath:indexPath
animated:NO
scrollPosition:UITableViewScrollPositionNone];
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
else
detailCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"detailCell3"forIndexPath:indexPath];
show2= NO;
cell.label.text = [self.array objectAtIndex:indexPath.row];
cell.image1.image = [UIImage imageNamed:[NSString stringWithFormat:[self.imageArray objectAtIndex:indexPath.row]]];
cell.imageButton.image = [UIImage imageNamed:@"Play_Symbol_copie_2@3x.png"];
// [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]] withRowAnimation:UITableViewRowAnimationMiddle];
[self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]]
withRowAnimation:UITableViewRowAnimationNone];
[self.tableView selectRowAtIndexPath:indexPath
animated:NO
scrollPosition:UITableViewScrollPositionNone];
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
else
if (indexPath.row == 3)
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[self.wiki objectAtIndex:pos]]];
UIWebView *video = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - +50)];
[video loadRequest:request];
video.delegate=self;
showWeb = YES;
UIActivityIndicatorView *actInd=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
actInd.color=[UIColor blackColor];
[actInd setCenter:self.view.center];
self.activityIndicator=actInd;
[self.view addSubview:video];
[video addSubview:self.activityIndicator];
这是在模拟器上的外观/工作方式: 关闭-
描述-
特征-
这就是真实设备的工作原理: 描述-
特征-
关闭- 和
我不知道这是否是问题,但是当我在真实设备中第一次按下后,行正在改变颜色。为什么?有什么想法吗?
【问题讨论】:
我猜你滚动时会发生这种情况? 没有。我的行只是没有关闭.. :( 不要开启滚动功能试试看 如果我禁用滚动功能,我看不到关于描述和carac的信息。 【参考方案1】:如果在模拟器中一切正常但在设备中运行良好,则检查“dequeueReusableCellWithIdentifier”/“CellID”值,因为模拟器不区分大小写,但设备区分大小写。
可能是找不到你的手机ID所以它发生了,我不确定但只检查一次。
【讨论】:
以上是关于表格视图在真实设备上不刷新的主要内容,如果未能解决你的问题,请参考以下文章
CMMotionManager:设备校准在真实设备上不起作用