所以我有一个 UITableView 加载了许多引号列。进入显示此数据的 UITableView 后,单元格最初似乎没有正确加载,文本看起来真的被压扁和/或切断,大约 1/2 秒后,它正确加载并且所有内容工作正常。
每次我加载表格 View 时都会发生这种情况。
例如:
这是 .estimatedrowheight 的问题...还是因为 View 无法足够快地将数据加载到 UITableView?然而,我尝试修改行高无济于事。
编辑
当我明确设置高度时,它看起来像这样 -
captionsTableView.rowHeight = 80
它工作得很好......因为每个单元格以 80 点的高度加载,没有初始加载故障。
但是使用 captionsTableView.rowHeight = UITableViewAutomaticDimension
和 captionsTableView.estimatedRowHeight = 80.0 打破它
编辑 2 - 代码
class CaptionsController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var captionSegment: UISegmentedControl!
@IBOutlet weak var captionText: UINavigationItem!
@IBOutlet weak var captionSearchBar: UISearchBar!
@IBOutlet weak var captionsTitle: UILabel!
var receiveImage:UIImage!
//var receiveCategoryText:String!
//var firstNameCell: UITableViewCell = UITableViewCell()
//var firstNameText: UITextField = UITextField()
var model:ModelData!
let tapRec = UITapGestureRecognizer()
var currentCell: UITableViewCell!
var fav: String!
let basicCellIdentifier = "CustomCells"
@IBOutlet weak var captionsTableView: UITableView!
var c: CustomCells!
var captionJSON: JSON = nil
override func viewDidLoad() {
super.viewDidLoad()
model = (self.tabBarController as CaptionTabBarController).model
captionJSON = model.quoteSelection()
captionText.title = model.categoryName
captionsTableView.delegate = self
captionsTableView.dataSource = self
self.navigationController?.navigationBar.titleTextAttributes = [ NSFontAttributeName: UIFont(name: "CherrySwash-Regular", size: 25)!, NSForegroundColorAttributeName: UIColor(red:0.0/255.0, green: 159.0/255.0, blue: 172.0/255.0, alpha: 1.0)]
configureTableView()
captionsTableView.reloadData()
tapRec.numberOfTapsRequired = 2
tapRec.addTarget(self, action: "tappedView")
self.view.addGestureRecognizer(tapRec)
self.view.userInteractionEnabled = true
}
func configureTableView() {
captionsTableView.rowHeight = UITableViewAutomaticDimension
captionsTableView.estimatedRowHeight = 80.0
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
//deselectAllRows()
//captionsTableView.reloadData()
}
override func viewDidAppear(animated: Bool) {
captionsTableView.reloadData()
}
func deselectAllRows() {
if let selectedRows = captionsTableView.indexPathsForSelectedRows() as? [NSIndexPath] {
for indexPath in selectedRows {
captionsTableView.deselectRowAtIndexPath(indexPath, animated: false)
}
}
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return captionJSON.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
return customCellAtIndexPath(indexPath)
}
func customCellAtIndexPath(indexPath:NSIndexPath) -> CustomCells {
var cell = captionsTableView.dequeueReusableCellWithIdentifier(basicCellIdentifier) as CustomCells
setTitleForCell(cell, indexPath: indexPath)
setSubtitleForCell(cell, indexPath: indexPath)
setImageForCell(cell, indexPath: indexPath)
return cell
}
func setTitleForCell(cell:CustomCells, indexPath:NSIndexPath) {
let item = captionJSON[indexPath.row]["quote"]
cell.mainLabel.text = item.stringValue
}
func setSubtitleForCell(cell:CustomCells, indexPath:NSIndexPath) {
let item = captionJSON[indexPath.row]["author"]
cell.creditLabel.text = item.stringValue
}
func setImageForCell(cell:CustomCells, indexPath:NSIndexPath) {
//let item = Array(Array(model.quoteItems.values)[indexPath.row])[1] as? String
//if (item == "fav") {
//cell.favImgView.image = UIImage(named: "icon-heart-fav")!
//} else {
cell.favImgView.image = UIImage(named: "icon-heart")!
//}
}
func tappedView(){
//need to add filled icon, as well as logic to not change image upon select of favorited cell
var image : UIImage = UIImage(named: "icon-heart-fav")!
c.favImgView.image = image
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
c = captionsTableView.cellForRowAtIndexPath(indexPath) as CustomCells
var captiontabBar:CaptionTabBarController = CaptionTabBarController()
model.quote = c.mainLabel.text!
model.author = c.creditLabel.text!
println(" quote!!! " + model.quote)
self.tabBarController?.selectedIndex = 0
//let secondViewController:SelectionsController = SelectionsController()
//self.presentViewController(secondViewController, animated: true, completion: nil)
//let returnController = self.storyboard!.instantiateViewControllerWithIdentifier("selections") as? UIViewController
//self.presentViewController(returnController!, animated: true, completion: nil)
/*for tempCell: UITableViewCell in tableView.visibleCells() as [UITableViewCell] {
var image : UIImage = UIImage(named: "icon-heart")!
tempCell.imageView?.image = image
}
var image : UIImage = UIImage(named: "icon-heart-overview")!
c.favImgView?.image = image*/
}
}
class CustomCells: UITableViewCell {
@IBOutlet var mainLabel: UILabel!
@IBOutlet var creditLabel: UILabel!
@IBOutlet var favImgView: UIImageView!
}
最佳答案
在 (void)viewWillAppear 中添加您的代码:
看起来您正在 viewDidload 中执行此操作。
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if (![self.p_tableView respondsToSelector:@selector(tableView:heightForRowAtIndexPath:)])
{
self.p_tableView.rowHeight = UITableViewAutomaticDimension;
self.p_tableView.estimatedRowHeight = 100.0f;
}
}
关于ios - UITableViewCells 初始加载 View /显示问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29263875/
我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格:Editingkategori{:action=>'update',:id=>@konkurrancer.id})do|f|%>'Trackingurl',:style=>'width:500;'%>'Editkonkurrence'%>|我的konkurrencer模型:has_one:link我的链接模型:classLink我的konkurrancer编辑操作:defedit@konkurrancer=Konkurrancer.find(params[:id])@konkurrancer.link_attrib
我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po
在我的gem中,我需要yaml并且在我的本地计算机上运行良好。但是在将我的gem推送到rubygems.org之后,当我尝试使用我的gem时,我收到一条错误消息=>"uninitializedconstantPsych::Syck(NameError)"谁能帮我解决这个问题?附言RubyVersion=>ruby1.9.2,GemVersion=>1.6.2,Bundlerversion=>1.0.15 最佳答案 经过几个小时的研究,我发现=>“YAML使用未维护的Syck库,而Psych使用现代的LibYAML”因此,为了解决
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
尝试通过RVM将RubyGems升级到版本1.8.10并出现此错误:$rvmrubygemslatestRemovingoldRubygemsfiles...Installingrubygems-1.8.10forruby-1.9.2-p180...ERROR:Errorrunning'GEM_PATH="/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/ruby-1.9.2-p180@global:/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/rub
我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何
我想要做的是有2个不同的Controller,client和test_client。客户端Controller已经构建,我想创建一个test_clientController,我可以使用它来玩弄客户端的UI并根据需要进行调整。我主要是想绕过我在客户端中内置的验证及其对加载数据的管理Controller的依赖。所以我希望test_clientController加载示例数据集,然后呈现客户端Controller的索引View,以便我可以调整客户端UI。就是这样。我在test_clients索引方法中试过这个:classTestClientdefindexrender:template=>
鉴于我有以下迁移:Sequel.migrationdoupdoalter_table:usersdoadd_column:is_admin,:default=>falseend#SequelrunsaDESCRIBEtablestatement,whenthemodelisloaded.#Atthispoint,itdoesnotknowthatusershaveais_adminflag.#Soitfails.@user=User.find(:email=>"admin@fancy-startup.example")@user.is_admin=true@user.save!ende
我的最终目标是安装当前版本的RubyonRails。我在OSXMountainLion上运行。到目前为止,这是我的过程:已安装的RVM$\curl-Lhttps://get.rvm.io|bash-sstable检查已知(我假设已批准)安装$rvmlistknown我看到当前的稳定版本可用[ruby-]2.0.0[-p247]输入命令安装$rvminstall2.0.0-p247注意:我也试过这些安装命令$rvminstallruby-2.0.0-p247$rvminstallruby=2.0.0-p247我很快就无处可去了。结果:$rvminstall2.0.0-p247Search
所以我在关注Railscast,我注意到在html.erb文件中,ruby代码有一个微弱的背景高亮效果,以区别于其他代码HTML文档。我知道Ryan使用TextMate。我正在使用SublimeText3。我怎样才能达到同样的效果?谢谢! 最佳答案 为SublimeText安装ERB包。假设您安装了SublimeText包管理器*,只需点击cmd+shift+P即可获得命令菜单,然后键入installpackage并选择PackageControl:InstallPackage获取包管理器菜单。在该菜单中,键入ERB并在看到包时选择