我刚刚完成了一个应用程序的开发,并决定将其安装到我的手机上。然后我发现我的表格 View 在我的手机上看起来不一样!
这是应该看到的。 (模拟器)
这是我看到的:(我的手机)
如您所见,我手机上的表格 View 单元格在我的手机上看起来“更长”,但在模拟器中,它看起来很正常。我不明白为什么会这样。你能告诉我为什么吗?
我的手机是 iPhone 6s Plus,运行 iOS 8.1.2。我的模拟器是 iPhone 6s Plus,运行 iOS 9.3
要重现这一点,请将 TableView Controller 添加到 Storyboard并将其放入原型(prototype)单元格中:
黑色边框是 ImageView 。
然后,您知道,只需像我一样在表格 View 中放置一些单元格。
以下是表格 View 的代码,以备不时之需:
class ColorSchemeController: UITableViewController {
var color: UIColor!
override func viewDidLoad() {
super.viewDidLoad()
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 5
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch section {
case 0...2:
return 3
case 3:
var h: CGFloat = 0
color.getHue(&h, saturation: nil, brightness: nil, alpha: nil)
if h == 0 {
return 3
}
return 5
case 4:
return 2
default:
return 0
}
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell1", forIndexPath: indexPath)
let imageView = cell.viewWithTag(1)! as! UIImageView
let label = cell.viewWithTag(2)! as! UILabel
func setColor(color: UIColor) {
imageView.backgroundColor = color
label.text = color.hexDescription()
}
switch indexPath.section {
case 0:
switch indexPath.row {
case 0:
setColor(self.color)
case 1:
setColor(self.color.rotateHueByDegrees(120))
case 2:
setColor(self.color.rotateHueByDegrees(-120))
default:
assert(false)
}
case 1:
switch indexPath.row {
case 0:
setColor(self.color)
case 1:
setColor(self.color.rotateHueByDegrees(150))
case 2:
setColor(self.color.rotateHueByDegrees(-150))
default:
assert(false)
}
case 2:
switch indexPath.row {
case 0:
setColor(self.color)
case 1:
setColor(self.color.rotateHueByDegrees(30))
case 2:
setColor(self.color.rotateHueByDegrees(-30))
default:
assert(false)
}
case 3:
switch indexPath.row {
case 0:
setColor(self.color)
case 1:
var h: CGFloat = 0
color.getHue(&h, saturation: nil, brightness: nil, alpha: nil)
if h == 0 {
var v: CGFloat = 0
self.color.getHue(nil, saturation: nil, brightness: &v, alpha: nil)
if v <= 0.1 {
setColor(self.color.incrementValueBy(0.1))
} else {
setColor(self.color.incrementValueBy(-0.1))
}
break
}
var s: CGFloat = 0
self.color.getHue(nil, saturation: &s, brightness: nil, alpha: nil)
if s <= 0.1 {
setColor(self.color.incrementSaturationBy(0.1))
} else {
setColor(self.color.incrementSaturationBy(-0.1))
}
case 2:
var h: CGFloat = 0
color.getHue(&h, saturation: nil, brightness: nil, alpha: nil)
if h == 0 {
var v: CGFloat = 0
self.color.getHue(nil, saturation: nil, brightness: &v, alpha: nil)
if v >= 0.9 {
setColor(self.color.incrementValueBy(-0.2))
} else {
setColor(self.color.incrementValueBy(0.2))
}
break
}
var s: CGFloat = 0
self.color.getHue(nil, saturation: &s, brightness: nil, alpha: nil)
if s >= 0.9 {
setColor(self.color.incrementSaturationBy(-0.2))
} else {
setColor(self.color.incrementSaturationBy(0.2))
}
case 3:
var v: CGFloat = 0
self.color.getHue(nil, saturation: nil, brightness: &v, alpha: nil)
if v <= 0.1 {
setColor(self.color.incrementValueBy(0.1))
} else {
setColor(self.color.incrementValueBy(-0.1))
}
case 4:
var v: CGFloat = 0
self.color.getHue(nil, saturation: nil, brightness: &v, alpha: nil)
if v >= 0.9 {
setColor(self.color.incrementValueBy(-0.2))
} else {
setColor(self.color.incrementValueBy(0.2))
}
default:
assert(false)
}
case 4:
switch indexPath.row {
case 0:
setColor(self.color)
case 1:
setColor(self.color.rotateHueByDegrees(180))
default:
assert(false)
}
default:
assert(false)
}
return cell
}
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
switch section {
case 0:
return "Triadic"
case 1:
return "Split Complements"
case 2:
return "Analogous"
case 3:
return "Monochromatic"
case 4:
return "Complements"
default:
return nil
}
}
}
如果您无法复制,这里是 github 链接:https://github.com//Sweeper777/ColorBible
下载 Xcode 项目并在您的手机上运行它。
最佳答案
我可以在模拟器8.1上重现同样的效果。
我注意到 tableView 的 rowHeight 设置为 -1 (UITableViewAutomaticDimension),所以这个问题与动态大小有关(不是确定为什么,在 iOS 8 中似乎是一种不同的行为)。
这似乎可以解决问题(假设您不需要动态调整大小):
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.rowHeight = 44;
}
关于ios - 为什么我的表格 View 单元格的高度在我的手机上如此之大,但在模拟器中却没有?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36370463/
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
我有一个模型:classItem项目有一个属性“商店”基于存储的值,我希望Item对象对特定方法具有不同的行为。Rails中是否有针对此的通用设计模式?如果方法中没有大的if-else语句,这是如何干净利落地完成的? 最佳答案 通常通过Single-TableInheritance. 关于ruby-on-rails-Rails-子类化模型的设计模式是什么?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.co
我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%
我主要使用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
我好像记得Lua有类似Ruby的method_missing的东西。还是我记错了? 最佳答案 表的metatable的__index和__newindex可以用于与Ruby的method_missing相同的效果。 关于ruby-难道Lua没有和Ruby的method_missing相媲美的东西吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/7732154/
我需要从一个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=>
为什么4.1%2返回0.0999999999999996?但是4.2%2==0.2。 最佳答案 参见此处:WhatEveryProgrammerShouldKnowAboutFloating-PointArithmetic实数是无限的。计算机使用的位数有限(今天是32位、64位)。因此计算机进行的浮点运算不能代表所有的实数。0.1是这些数字之一。请注意,这不是与Ruby相关的问题,而是与所有编程语言相关的问题,因为它来自计算机表示实数的方式。 关于ruby-为什么4.1%2使用Ruby返
我有一个奇怪的问题:我在rvm上安装了rubyonrails。一切正常,我可以创建项目。但是在我输入“railsnew”时重新启动后,我有“程序'rails'当前未安装。”。SystemUbuntu12.04ruby-v"1.9.3p194"gemlistactionmailer(3.2.5)actionpack(3.2.5)activemodel(3.2.5)activerecord(3.2.5)activeresource(3.2.5)activesupport(3.2.5)arel(3.0.2)builder(3.0.0)bundler(1.1.4)coffee-rails(
是的,我知道最好使用webmock,但我想知道如何在RSpec中模拟此方法:defmethod_to_testurl=URI.parseurireq=Net::HTTP::Post.newurl.pathres=Net::HTTP.start(url.host,url.port)do|http|http.requestreq,foo:1endresend这是RSpec:let(:uri){'http://example.com'}specify'HTTPcall'dohttp=mock:httpNet::HTTP.stub!(:start).and_yieldhttphttp.shou