小编Chr*_*sen的帖子

如何以编程方式更新UIView的恒定高度约束?

我有一个UIView和我使用Xcode Interface Builder设置约束.

现在我需要以UIView's编程方式更新高度常量.

有一个功能myUIView.updateConstraints(),但我不知道如何使用它.

xcode autolayout nslayoutconstraint swift ios-autolayout

78
推荐指数
8
解决办法
10万
查看次数

用动画交换rootViewController?

我试图用标签栏交换到另一个根视图控制器; 通过app委托,我想添加过渡动画.默认情况下,它只显示没有任何动画的视图.

let tabBar = self.instantiateViewController(storyBoard: "Main", viewControllerID: "MainTabbar")
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.window = UIWindow(frame: UIScreen.main.bounds)
appDelegate.window?.rootViewController = tabBar
appDelegate.window?.makeKeyAndVisible()
Run Code Online (Sandbox Code Playgroud)

这就是我交换到另一个rootview控制器的方式.

xcode uiviewanimation rootview swift swift3

54
推荐指数
6
解决办法
2万
查看次数

如何根据设备屏幕大小调整集合视图单元格的大小?

我注意到单元格总是遵循尺寸检查器中的定义.即使我已经应用了UICollectionViewDelegateFlowLayout.

在此输入图像描述

在此输入图像描述

这就是它的外观.但我希望这些细胞看起来更像是在更小的iPhone屏幕上.

在此输入图像描述

ios uicollectionview ios10

17
推荐指数
5
解决办法
3万
查看次数

将base64数据解码为图像

此代码不再适用于Swift 3.

imageData = NSData(base64EncodedString: mediaFile, options: NSDataBase64DecodingOptions.fromRaw(0)!)
Run Code Online (Sandbox Code Playgroud)

这是一个.

imageData = NSData(base64EncodedString: mediaFile, options: .allZeros)
Run Code Online (Sandbox Code Playgroud)

base64 uiimage nsdata swift3 xcode8

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

集合视图单元格按钮不触发动作

所以我在集合视图单元格 xib 中有一个看起来像铅笔的按钮。

在此处输入图片说明

然后我有这个代码。

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "groupsCollectionViewCellIdentifier", for: indexPath) as! GroupCollectionViewCell

    //add action to the edit button
    cell.editButton.tag = indexPath.row
    cell.editButton.addTarget(self, action: #selector(GroupsCollectionViewController.editGroupAction), for: .touchUpInside)

    return cell
}

//segue to edit group
func editGroupAction() {
    performSegue(withIdentifier: "editGroupSegue", sender: self)
}
Run Code Online (Sandbox Code Playgroud)

但是每当我单击编辑按钮时。什么都没有发生。我想知道缺少什么。

xcode uibutton uicollectionview uicollectionviewcell swift

9
推荐指数
3
解决办法
8939
查看次数

如何在集合视图单元格中添加uibutton操作?

在此输入图像描述

所以我有这个集合视图,其中包含一个包含编辑按钮的单元格,位于右上角.如何将动作连接到其中?

我尝试添加cell.editbutton.addTargetcollectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell,但它不会检测touchUpInside事件.

uibutton uicollectionview uicollectionviewcell swift swift3

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

如何在UICollectionView中显示多个部分

集合视图仅显示第一部分,但不显示第二部分.

这是代表们

private func numberOfSectionsInCollectionView(collectionView: UICollectionView!) -> Int {
    return 2
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {

    var returnValue = Int()

    if section == 0 {
        returnValue = 1

    } else if section == 1 {
        returnValue = self.section1DataSource.count

    }

    return returnValue

}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    var cell = UICollectionViewCell()

    let cellA:GroupPhoto = collectionView.dequeueReusableCell(withReuseIdentifier: "groupPhotoCard", for: indexPath) as! GroupPhoto
    let cellB:AddFriendCell = collectionView.dequeueReusableCell(withReuseIdentifier: "addFriendCard", for: indexPath) as! AddFriendCell …
Run Code Online (Sandbox Code Playgroud)

uicollectionview uicollectionviewcell swift swift3

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

Facebook Open Graph 属性不起作用:“应该明确提供 'og:image' 属性,即使可以从其他标签推断出一个值。”

所以我有这个网站:http : //asimpleforexguide.com/

我已经使用从 Facebook 生成的 app_id 指定了 Open Graph 属性。

<meta property="fb:app_id" content="277549136353523" />
<meta property="og:title" content="ASDFG - A Simply Direct Forex Guide" />
<meta property="og:type" content="website" />
<meta property="og:url" content="http://www.asimpleforexguide.com/" />
<meta property="og:image" content="http://www.asimpleforexguide.com/img/bg-mobile-icon.jpg" />
<meta property="og:description" content="Learn Forex Trading from setting up accounts, to setting up trades." />
Run Code Online (Sandbox Code Playgroud)

但是每当我分享链接或在 Facebook 共享调试器中尝试时,我都会收到这些错误。

推断属性
'og:image' 属性应该明确提供,即使可以从其他标签推断出一个值。
缺少属性

缺少以下必需属性:og:url、og:type、og:title、og:image、og:description、fb:app_id

meta-tags facebook-sharer facebook-opengraph

5
推荐指数
0
解决办法
1090
查看次数

如何使用CNContact.predicateForContacts检索所有联系人?

所以我有这个代码工作正常,但只有你在predicateForContacts参数中指定了一个名称.

func retrieveContactsWithStore(store: CNContactStore) {
    do {
           let predicate = CNContact.predicateForContacts(matchingName: "John")
           let keysToFetch = [CNContactFormatter.descriptorForRequiredKeys(for: .fullName), CNContactPhoneNumbersKey] as [Any]

           let contacts = try store.unifiedContacts(matching: predicate, keysToFetch: keysToFetch as! [CNKeyDescriptor])
           self.objects = contacts
           DispatchQueue.main.async(execute: { () -> Void in
               self.myTableView.reloadData()
           })
       } catch {
           print(error)
       }
}
Run Code Online (Sandbox Code Playgroud)

我想检索地址簿上列出的所有人的姓名.

swift cncontact cncontactstore swift3

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

如何从UITableViewCell获取文本字段的值?

所以我有这个UITableView单元格有4个UITextField,我想在按钮点击时得到它们的值.

此代码不检索任何值.

@IBAction func printBtnAction(_ sender: Any) {

    let cell = self.myTableView.dequeueReusableCell(withIdentifier: "manualAddC1") as! AddFriendC1Cell

    let alias = cell.aliasTextField.text!
    let primaryPhone = cell.primaryPhoneTextField.text!
    let secondaryPhone = cell.seondaryPhoneTextField.text!
    let email = cell.emailAddressTextField.text!

    print("Alias: \(alias), Phone: \(primaryPhone), Phone2: \(secondaryPhone), Email: \(email)")
}
Run Code Online (Sandbox Code Playgroud)

这是TableView的屏幕截图 在此输入图像描述

xcode uitableview swift swift3

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

如何在应用程序运行时检测用户是否更改了 iPhone 系统语言设置?

我将使用这些语言更改作为我将要编写的代码中的触发器。

例如:

if languageHasChanged() {
    //do something
}
Run Code Online (Sandbox Code Playgroud)

ios swift swift3

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

如何使用SwiftyJson解析JSON

这是数据

[{
  "mineral": "Phosphorus",   
  "data": [ 7.65, 19.74, 15.48 ]
},

{
  "mineral": "Calcium",   
  "data": [ 1.65, 1.32, 1.78 ]
}]
Run Code Online (Sandbox Code Playgroud)

这是我用来解析它的代码.

if let dataFromString = self.response.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false) {

        let json = JSON(data: dataFromString)

        var valuesB = [Double]()

        for i in 0..<json.count {
            self.nutrient.append(json[i]["mineral"].stringValue)
            print("Nutrient: \(json[i]["mineral"].stringValue)\n")

            for j in 0..<json[i]["data"].count {
                valuesB.append(json[i]["data"][j].doubleValue)
                print("Values: \(json[i]["data"][j].doubleValue)")
            }

            values.append(valuesB)
        }
   }
Run Code Online (Sandbox Code Playgroud)

但我得到的只是

Nutrient: Phosphorus

Values: 0.0
Values: 0.0
Values: 0.0

Nutrient: Calcium

Values: 0.0
Values: 0.0
Values: 0.0
Run Code Online (Sandbox Code Playgroud)

我正在使用SwiftyJson将Xcode 7与Swift一起使用,还有另外一种方法可以使用SwiftyJson吗?

xcode json swift swifty-json swift2

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