小编Man*_*son的帖子

viewDidLoad中之前和之后的区别

我试图设置searchBartableHeaderView内部viewDidLoad:

 override func viewDidLoad() {
    super.viewDidLoad()


    // SearchController initializiation
    self.searchController = UISearchController.init(searchResultsController: nil)
    self.searchController.delegate = self
    self.searchController.searchBar.delegate = self
    self.searchController.searchBar.sizeToFit()
    self.searchController.searchResultsUpdater = self
    self.searchController.searchBar.barTintColor = UIColor.white
    self.searchController.searchBar.keyboardAppearance = .default
    self.searchController.searchBar.backgroundColor = UIColor.white
    self.searchController.hidesNavigationBarDuringPresentation = true
    self.searchController.obscuresBackgroundDuringPresentation = false


    self.tableView.tableHeaderView = self.searchController.searchBar
    self.definesPresentationContext = true

    self.fetch()
    self.tableView.reloadData()

}
Run Code Online (Sandbox Code Playgroud)

这是我的fetch()功能:

func fetch() {
    let fetchRequest:NSFetchRequest<Phone> = Phone.fetchRequest()
    fetchRequest.sortDescriptors = [NSSortDescriptor.init(key: "header", ascending: true), NSSortDescriptor.init(key: "date", ascending: true)]

    self.fetchedResultsController = NSFetchedResultsController.init(fetchRequest: fetchRequest, managedObjectContext: self.managedObjectContext, sectionNameKeyPath: …
Run Code Online (Sandbox Code Playgroud)

core-data viewdidload swift uisearchcontroller

12
推荐指数
1
解决办法
496
查看次数

无法调用非函数类型的值:UITableView

我有一个延伸的SwiftUITableViewController.它有这个功能

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {...}
Run Code Online (Sandbox Code Playgroud)

有必要,我需要在一个地方以编程方式调用此函数

self.tableView(tableView, cellForRowAt: 1)
Run Code Online (Sandbox Code Playgroud)
  • 我明白了,不能调用非函数类型'UITableView!'的值

如何以编程方式调用此函数?

uitableview ios swift

8
推荐指数
1
解决办法
3693
查看次数

UITableViewCell最小高度,自动调整单元格大小

我正在使用自动调整项目中的单元格大小.我希望将单元格保持在最小值height,但是我无法在内容视图中为我的单元格设置最小height 约束(因为它在" 添加新约束"视图中显示为灰色:

在此输入图像描述

无论如何都要为我的细胞添加最小height 约束

uitableview tableviewcell ios autolayout swift

6
推荐指数
3
解决办法
5413
查看次数


在没有重装数据的情况下更改UICollectionView中的标签值?

我正在使用swift 2.2,我在单元格内部有一个集合视图,我有一个标签.我想在按钮点击的UICollection视图中更改标签文本值,而不使用重新加载整个uiCollection视图.我无法在我的场景中使用collectionView.reloadData().我希望不使用它就可以.只是为了更新collectionview中特定项目中的一个标签.任何帮助?

ios uicollectionview swift

5
推荐指数
2
解决办法
3006
查看次数

使用未解析的标识符“存在” - 当前方法不再有效

我打算使用,UIAlertController但是当我想展示它时,我看到了这个错误:

使用未解析的标识符“存在”

这是我的代码:

func showAllert(title: String, msg: String, vc: UIViewController){
    let alert = UIAlertController(title: title, message: msg, preferredStyle: .alert)
    let action = UIAlertAction(title: "ok", style: .default, handler: nil)
    alert.addAction(action)

    present(alert, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)

ios swift uialertcontroller

4
推荐指数
1
解决办法
7123
查看次数

TabBar图标反弹对选择的影响,例如Swift中的Twitter应用程序

当我点击其中一个时,如何创建类似Twitter应用程序的标签栏图标弹跳效果?看起来像按比例缩小,然后又恢复正常。

在此处输入图片说明

谢谢。

uitabbarcontroller uitabbaritem uitabbar ios swift

3
推荐指数
1
解决办法
1079
查看次数

#selector 与闭包不兼容?

我试图用闭包来实现自定义函数。但它不受#selector.

下面是一个例子:

class Core: NSObject {

    static let shared:Core = Core.init()


    func button(viewController: UIViewController, button: UIButton, title: String, color: UIColor, completion: () -> Void) {

        button.layer.cornerRadius = button.bounds.width / 2
        button.setTitle(title, for: .normal)
        button.setTitleColor(UIColor.white, for: .normal)
        button.backgroundColor = color
        button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 18)
        button.addTarget(viewController, action: #selector(completion()), for: .touchUpInside)
    }
}
Run Code Online (Sandbox Code Playgroud)

Xcode 给了我一个构建时间问题:

“#selector”的参数不引用“@objc”方法、属性或初始值设定项

closures func selector swift

3
推荐指数
1
解决办法
1150
查看次数

使用ObjectMapper将String类型JSON转换为Integer

我有我的模特课

class CPOption : Object, Mappable
{

dynamic var optionId : Int64 = 0

override static func primaryKey() -> String? {
    return "optionId"
}

required convenience init?(map: Map) {
    self.init()
}

func mapping(map: Map) {

    optionId     <- map["id"] //**Here i need to transform string to Int64**
}
}
Run Code Online (Sandbox Code Playgroud)

我的输入JSON包含optionId作为String.

"options": [
            {
                "id": "5121",
            },
        ]
Run Code Online (Sandbox Code Playgroud)

我需要在Objectmapper Map函数中将此传入的字符串类型转换为Int64.

json realm swift objectmapper

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

在启动屏幕中隐藏状态栏

默认情况下,启动屏幕提供状态栏。是否可以在启动屏幕中隐藏状态栏,例如Twitter应用程序(iOS)。

uistatusbar swift launch-screen swift3

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

像 WhatsApp 一样为导航设置标题和副标题

private func setTitle(title:String, subtitle:String, animate: Bool) -> UIView {
    let titleLabel = UILabel(frame: CGRect(x:0, y:-5, width:0, height:0))

    titleLabel.backgroundColor = UIColor.clear
    titleLabel.textColor = UIColor.gray
    titleLabel.font = UIFont.boldSystemFont(ofSize: 15)
    titleLabel.text = title
    titleLabel.adjustsFontSizeToFitWidth = true

    let subtitleLabel = UILabel(frame: CGRect(x:0, y:18, width:0, height:0))
    subtitleLabel.backgroundColor = UIColor.clear
    subtitleLabel.textColor = UIColor.black
    subtitleLabel.font = UIFont.systemFont(ofSize: 12)
    subtitleLabel.text = subtitle
    subtitleLabel.adjustsFontSizeToFitWidth = true


    let titleView = UIView(frame: CGRect(x:0, y:0, width:max(titleLabel.frame.size.width, subtitleLabel.frame.size.width), height:30))
    let titleViewTapGesture = UITapGestureRecognizer(target: self, action: #selector(titleViewTapped(sender:)))
    titleView.addGestureRecognizer(titleViewTapGesture)
    titleView.addSubview(titleLabel)

    if animate{
        subtitleLabel.alpha = 0.0 …
Run Code Online (Sandbox Code Playgroud)

uiview uinavigationcontroller uilabel ios swift

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

如何在CALayer上居中CGImage?

我试图设置UIImageCGImage作为layer的内容,然后添加layerviewlayer
黄色视图的中心应该是五颗星。那就是我想要的。
不过好像星星的中心与对齐originview。我该怎么做才能纠正它?

func putOnStars() {
    let rect = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height))
    rect.backgroundColor = .yellow
    view.addSubview(rect)

    let baseLayer = CALayer()
    baseLayer.contents = UIImage(named: "stars")?.cgImage
    baseLayer.contentsGravity = kCAGravityCenter
    rect.layer.addSublayer(baseLayer)

}
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明 如果您要测试,这是为您提供的星图。 在此处输入图片说明

calayer cgimage swift

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