ios - XCode UITable 滚动更改文本值

标签 ios uitableview

我有一个奇怪的问题。

我从在线加载值并显示在我的 UITableViewCell 中。它工作正常...我面临的问题是,如果我相应地向下滚动应用程序从在线获取,但是当我向上滚动时,值匹配正确...

如果 strLocation 不为 null 我将显示 LocationImageView,如果 strLocation 为 null 我将隐藏 LocationImageView .当我最初加载应用程序时,它工作正常,当我滚动表格并向下移动时,如果某些值的 strLocation 为空白,它隐藏了 LocationImageView 但发生了什么,在表的顶部,strLocation 不为空,在那些地方 LocationImageView 也被隐藏。

我想知道如何解决这个问题

cell.cityLabel.text = [dictionary valueForKey:@"location"];

NSString *strLocation = [dictionary valueForKey:@"location"];


if ([strLocation isEqual:@""]){
    cell.LocationImageView.hidden=TRUE;
}

最佳答案

处理细胞时的标准问题。 UITableView(如果使用得当)会重复使用单元格,因此您需要正确更新单元格。如果您允许隐藏某些组件,您还需要放置一个代码,以便在数据允许的情况下显示该组件。查看您的代码段,您只是隐藏了组件,但无法将其返回。

我想看看你的代码是这样做的:

cell.LocationImageView.hidden=[strLocation isEqual:@""];

应该可以解决问题。

关于ios - XCode UITable 滚动更改文本值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29834269/

相关文章:

objective-c - 应用在initWithStyle上崩溃

ios - 无法将 tableView 或 collectionView 中选定的图像中的 imageView 提供给详细 View

objective-c - 如何限制 iOS 中 NSInteger 的最大数量?

ios - cellForRowAtIndexPath 中 if 条件中的多个 return 语句抛出 "Control may reach end of non-void function"错误

ios - 如何使 tableViewCell Size 自动?

ios - Firebase 存储如何在 Swift 中获取上传图片的进度

iphone - 这是开发了哪些控件? (见图)我相信它是 UITableView 但不知道如何

iOS 背景图像在 iPad 中重复出现?

objective-c - 如何在.plist中写入数据?

ios - 当我展开 UITextView 时,滚动不起作用