我有一个UIView和我使用Xcode Interface Builder设置约束.
现在我需要以UIView's编程方式更新高度常量.
有一个功能myUIView.updateConstraints(),但我不知道如何使用它.
我试图用标签栏交换到另一个根视图控制器; 通过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控制器的方式.
我注意到单元格总是遵循尺寸检查器中的定义.即使我已经应用了UICollectionViewDelegateFlowLayout.
这就是它的外观.但我希望这些细胞看起来更像是在更小的iPhone屏幕上.
此代码不再适用于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) 所以我在集合视图单元格 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)
但是每当我单击编辑按钮时。什么都没有发生。我想知道缺少什么。
所以我有这个集合视图,其中包含一个包含编辑按钮的单元格,位于右上角.如何将动作连接到其中?
我尝试添加cell.editbutton.addTarget的collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell,但它不会检测touchUpInside事件.
集合视图仅显示第一部分,但不显示第二部分.
这是代表们
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) 所以我有这个网站: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
所以我有这个代码工作正常,但只有你在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)
我想检索地址簿上列出的所有人的姓名.
所以我有这个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)
我将使用这些语言更改作为我将要编写的代码中的触发器。
例如:
if languageHasChanged() {
//do something
}
Run Code Online (Sandbox Code Playgroud) 这是数据
[{
"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吗?