swift3

Obtaining a View Controller Reference

喜欢而已 提交于 2019-12-12 04:33:07
问题 I read quite a few questions and answers no this problem. Some are for Ojective C. Some are for iOS. The ones that were close to what I need didn't work. I've set up a protocol for delegation. It doesn't work. The problem is that delegate variable isn't set. I need the reference to an active controller. Delegator protocol SwitchTabDelegate: class { func selectTab(tab: Int) } class ViewController: NSViewController { weak var delegate: SwitchTabDelegate? override func viewDidLoad() { super

Convert string to date with timezone

你离开我真会死。 提交于 2019-12-12 04:33:05
问题 i have date string 2017-01-03T10:45:00.000+02:00 and I need to transfer it to something like this 2017-01-03 10:45:00 +0200 let formatter = DateFormatter() formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ" // this formatter returning 2017-01-03 08:45:00 +0000 but I need // 2017-01-03 10:45:00 +0200 Thank you for your help! 回答1: Try this, Swift 3.0 let dateStr = "2017-01-03T10:45:00.000+02:00" let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd\'T\'HH:mm:ss\'.000\'z"

Dynamic Cell Re-sizing with UITextView within UITableViewCell causes warning?

谁说胖子不能爱 提交于 2019-12-12 04:31:46
问题 Currently in my code, I'm programmatically adding a UITextView within a UITableViewCell and added the ability to auto-resize the cell based on how much content is typed by the user. It currently looks like so: override func viewDidLoad() { tableView.estimatedRowHeight = 30.0 tableView.rowHeight = UITableViewAutomaticDimension } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { // Dequeue the cell to load data let cell: UITableViewCell =

CollectionView in TableViewCell scroll isn't smooth in swift3

╄→гoц情女王★ 提交于 2019-12-12 04:31:22
问题 In my project CollectionView in TableViewCell isn't display and I added cell.collectionView.reloadData() in my code. After I added, CollectionView displayed in TableViewCell , but ScrollView isn't smooth. How to solve this problem. If someone have any experience or ideas help me. Thanks. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "homecell") as! HomeCategoryRowCell let mainThemeList

perform segue and send tuple as sender

风格不统一 提交于 2019-12-12 04:29:01
问题 I've been trying to set a tuple to the sender object when doing a perform segue like: performSegue(withIdentifier: "", sender: ("hello", "hello2")) But inside override func prepare(for segue: UIStoryboardSegue, sender: Any?) I'm getting cast exception when trying to cast sender as (String, String) It seems that only the first element of the tuple is in sender . I'd expect since sender is of type Any? I could use a tuple as variable? Has anyone else experienced this? 回答1: Per the documentation

AppDelegate didFinishLaunchingWithOptions launchOptions - terminating with uncaught exception of type NSException Swift 3.0

邮差的信 提交于 2019-12-12 04:28:18
问题 I'm trying to create login/protected page session page using Swift 3.0 Therefore, I created didFinishLaunchingWithOptions launchOptions function in AppDelegate.swift as below AppDelegate.swift import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application

Convert UITextField to Integer in Xcode 8 and Swift 3 and calculate with them

不打扰是莪最后的温柔 提交于 2019-12-12 04:26:21
问题 I searched the whole internet but only found solutions for Swift 2 or outdated Xcode versions which doesnt help me :/ Also Im very new to Xcode and Swift, so please excuse that. I want the user to input some numbers in several UITextFields and then press a "calculate" button which shows the result in a UILabel. What I tested so far: Convert input data to Integer in Swift Swift calculate value of UITextFields and return value So my code looks really poor so far. Nothing worked so thats all I

iOS app crashes after deleting the last cell in section

风流意气都作罢 提交于 2019-12-12 04:25:58
问题 So I've my app crashing everytime I try to delete the last cell of the section. Ex., if my section has 10 rows, I can delete them without any problem but the last one throws the following error: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of sections. The number of sections contained in the table view after the update (1) must be equal to the number of sections contained in the table view before the update (3), plus or

IOS swift how can I get label text inside a TableView on label tap

十年热恋 提交于 2019-12-12 04:24:00
问题 I have a TableView that has data inside of it via Labels. When you click the label the Tap registers but now I would like to get the Data of the clicked label and I am having a difficult time getting that done. I have the same functionality working for Buttons for instance this is how I do it for my buttons inside a TableView . Button Click Event var locations = [String]() @IBOutlet weak var Location: UIButton! override func viewDidLoad() { super.viewDidLoad() TableSource.dataSource = self }

Swift 3 - Extract JSON data

徘徊边缘 提交于 2019-12-12 04:23:35
问题 I have the following JSON { "results" : [ { "address_components" : [ { "long_name" : "OL12 7LD", "short_name" : "OL12 7LD", "types" : [ "postal_code" ] }, { "long_name" : "Ings Lane", "short_name" : "Ings Ln", "types" : [ "route" ] }, { "long_name" : "Rochdale", "short_name" : "Rochdale", "types" : [ "postal_town" ] }, { "long_name" : "Greater Manchester", "short_name" : "Greater Manchester", "types" : [ "administrative_area_level_2", "political" ] }, { "long_name" : "England", "short_name" :