小编Joe*_*Joe的帖子

如何知道水龙头是在景观内还是在外面

我正在尝试开发代码部分,以检查我的tap是在视图内还是在视图外部,我尝试使用pointInside方法.如果A是主视图控制器而B是A的子视图,我怎样才能知道用户在B内部轻敲.

point uiviewcontroller uiview ios swift

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

viewContext 没有保存在数据库中(app.sqlite)

我创建了一个应用程序来保存学生的详细信息,使用 NSPersistanceContainer 并且当我从 JSON 获取数据并保存到 db 时,当时我得到的获取结果计数 > 0。如果我重新启动应用程序获取结果计数返回 0。

lazy var persistentContainer: NSPersistentContainer = {

    let container = NSPersistentContainer(name: "Students_dev")

    let storeURL = try! FileManager
        .default
        .url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
        .appendingPathComponent("Students_dev.sqlite")
    print("URL :",storeURL)

    let storeDescription = NSPersistentStoreDescription(url: storeURL)
    storeDescription.shouldMigrateStoreAutomatically = true
    storeDescription.shouldMigrateStoreAutomatically = true
    container.viewContext.automaticallyMergesChangesFromParent = true
    container.persistentStoreDescriptions = [storeDescription]

    container.loadPersistentStores(completionHandler: { (storeDescription, error) in
        if let error = error as NSError? {
            fatalError("Unresolved error \(error), \(error.userInfo)")
        }
    })
    return container
}()

// MARK: - …
Run Code Online (Sandbox Code Playgroud)

persistence core-data ios swift

8
推荐指数
2
解决办法
4356
查看次数

UISwitch开/关图像不能正常工作iOS10

我是iOS的新手,而我正试图在UIStoryboard中向UISwitch添加开/关图像,但它不起作用.它在iOS 10中已被弃用.我也尝试了代码,但它不起作用.

elseSwitch.onImage = UIImage(named: "switchOff")
elseSwitch.offImage = UIImage(named: "switchOff")
Run Code Online (Sandbox Code Playgroud)

它不起作用.[![在此输入图像描述] [1]] [1]

iphone uiswitch ios swift ios10

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

如何创建单列集合视图?

我正在尝试创建一个包含 1 列的 collectionView

func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
    return 1
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return 10
}
Run Code Online (Sandbox Code Playgroud)

但这没有用。主要问题是我的单元格大小动态变化。那么我可以将列限制为1吗?我需要按行加载单元格,而不是按列加载。

ios uicollectionviewcell uicollectionviewlayout swift

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

推动Viewcontroller通过导航控制器,显示黑屏

我正在堆栈溢出中搜索这个问题,但无法得到问题的确切答案,我被困在它很长一段时间.我的问题是我试图通过导航控制器推送TestViewController.当我点击按钮时,TestViewController正在加载导航栏,而UIScreen是黑色的.

TestViewController的代码

import UIKit
class TestViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }   

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(true)
        navigationItem.title = "Test page"
    }
}
Run Code Online (Sandbox Code Playgroud)

按钮代码

@IBAction func secondButtonClicked(sender: AnyObject) {
    buttonPressedNumber = "Two Clicked"
    buttonTextColor = UIColor.magentaColor()
      let a = TestViewController()
      let b:UIViewController = a as UIViewController
      navigationController?.pushViewController(b, animated: false)
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

uinavigationcontroller ios swift

4
推荐指数
3
解决办法
6672
查看次数

如何在swift中设置数组起始和结束索引?

我试图在操场上创建一个1-100个元素的数组,但是当我试图打印它时不会打印数组中的值.

码:

var ab:Array = [1...100]

for i in ab {
    print(i)
}
Run Code Online (Sandbox Code Playgroud)

输出: 在此输入图像描述

但是在操场上它没有显示任何错误.我做错了什么吗?谢谢

arrays swift swift-playground

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