小编Tol*_*ldy的帖子

ios UIScrollView有一个错误的默认contentOffset - swift

我在主View中的ScrollView中有一个View

问题是我的scrollView有一个错误的默认contentOffset.他的价值是(0,-64)

Apple医生说

默认值为CGPointZero.

我将此代码放在我的控制器上以临时处理它:

dispatch_async(dispatch_get_main_queue(), {
  self.scrollView.setContentOffset(CGPointZero, animated:false)
})
Run Code Online (Sandbox Code Playgroud)

为什么我的contentOffset没有好的默认值?

xcode scrollview ios swift

11
推荐指数
2
解决办法
1万
查看次数

如果让var - Unwrapping可选值

有一些方法可以展开可选值:

// 1st way
var str: String? = "Hello, playground"
if let strUnwrapped = str {
    // strUnwrapped is immutable
    println(strUnwrapped)
}

// 2nd way
var str: String? = "Hello, playground"
if var strUnwrapped = str {
    // strUnwrapped is mutable
    strUnwrapped = "Toldino"
    println(strUnwrapped)
}
Run Code Online (Sandbox Code Playgroud)

但我最近测试了以下一个......

// The strangest one
var str: String? = "Hello, playground"
if let var strUnwrapped = str {
    // strUnwrapped is mutabe
    strUnwrapped = "yolo"
    println(strUnwrapped)
}
Run Code Online (Sandbox Code Playgroud)

你能解释一下为什么它有用吗?这是一个错误或功能?

编辑

正如niñoscript所说,这是一个错误.

它在Swift 2.0中得到了解决,我用新版本尝试了它,它不再编译了. …

ios swift

7
推荐指数
1
解决办法
3146
查看次数

Swift 3.0 UITableViewDelege Objective-c方法与需求的选择器不匹配

我最近使用Xcode 8.0将一个项目转换为Swift 3,我对一个我不太了解的函数出错了.在这些方面:

extension HomeTableViewController : UITableViewDelegate {

    func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {

    }
}
Run Code Online (Sandbox Code Playgroud)

为了解决这个错误,Xcode告诉我@objc(tableView:commitEditingStyle:forRowAtIndexPath:)在方法之前添加.

Xcode错误

好的,它有效,但我不明白为什么它只需要这种方法.

Xcode不需要在我面前添加@objc的东西, tableView:heighForHeaderInSection但我没有看到UITableViewDelegate这个方法和之间的 任何差异tableView:commitEditingStyle:forRowAtIndexPath:.

那么,知道为什么这个tableView:commitEditingStyle:forRowAtIndexPath方法是强制性的?

提前致谢!

swift swift3

7
推荐指数
1
解决办法
1535
查看次数

标签 统计

swift ×3

ios ×2

scrollview ×1

swift3 ×1

xcode ×1