swift3

UITableView scroll to bottom from current position

老子叫甜甜 提交于 2021-01-27 18:46:27
问题 How can I scroll to last row in tableview from current positon, because I have tried this solution: self.tableView.scrollToRow(at: lastIndex.last!, at: .bottom , animated: false) let numberOfSections = self.tableView.numberOfSections let numberOfRows = self.tableView.numberOfRows(inSection: numberOfSections-1) if numberOfRows > 0 { let indexPath = IndexPath(row: numberOfRows-1, section: (numberOfSections-1)) self.tableView.scrollToRow(at: indexPath, at: .bottom, animated: animated) } and it

Get Random String from an Array [duplicate]

浪尽此生 提交于 2021-01-27 18:45:17
问题 This question already has answers here : Get random elements from array in Swift (5 answers) Closed 4 years ago . I am trying to get a random string from array "firstArray" and print it in UILabel "label". I cannot seem to figure it out and I get errors. Your help is appreciated. I tried searching but could not find any up-to-date tutorials/methods. import UIKit class ViewController: UIViewController { @IBOutlet var label: UILabel! @IBAction func random(_ sender: Any) { let firstArray = [ "hi

Swift 3.0 sort - Argument passed to call that takes no arguments

旧时模样 提交于 2021-01-27 12:44:37
问题 I am currently trying to port some Swift 2 code to Swift 3.0. Here is one line of code that is driving me crazy. public private(set) var searchHistory: [SearchHistoryEntry] = [SearchHistoryEntry]() // Struct that is cComparable .... ... searchHistory.sortInPlace({ $0.lastUsage.isAfter($1.lastUsage) }) This is my Swift 3.0 Version searchHistory.sort(by:{ $0.lastUsage.isAfter($1.lastUsage) }) lastUsage is of Type Date The Compiler complains with the following error message Argument passed to

2D Array extension Swift 3.1.1

怎甘沉沦 提交于 2021-01-27 04:56:23
问题 I am trying to make an Array extension in Swift 3.1.1 that supports the addition of an object to a certain index in a 2D Array even if the array hasn't been populated yet . The extension should also provide the ability to get an object at certain indexPath . I have the code for this in Swift 2 but I don't seem to be able to migrate it to Swift 3. This is the Swift 2 code: extension Array where Element: _ArrayProtocol, Element.Iterator.Element: Any { mutating func addObject(_ anObject :

How to dismiss and pop to viewcontroller simultaneously

别来无恙 提交于 2021-01-27 04:22:10
问题 My home viewcontroller is Tabbarcontroller From tabbar i navigate to (A) Viewcontroller (TabarViewcontroller -> A (Viewcontroller) From A (Viewcontroller) i push (B) Viewcontroller From B (Viewcontroller) i Present (C) Viewcontroller When i dismiss (c) Viewcontroller i want to show (A) Viewcontroller or (Home) TabbarviewController So, I want to first dismiss presented viewcontroller and then I want to pop my previous pushed controller Here is my navigation flow From Tabbarviewcontroller 1-

How to dismiss and pop to viewcontroller simultaneously

五迷三道 提交于 2021-01-27 04:22:09
问题 My home viewcontroller is Tabbarcontroller From tabbar i navigate to (A) Viewcontroller (TabarViewcontroller -> A (Viewcontroller) From A (Viewcontroller) i push (B) Viewcontroller From B (Viewcontroller) i Present (C) Viewcontroller When i dismiss (c) Viewcontroller i want to show (A) Viewcontroller or (Home) TabbarviewController So, I want to first dismiss presented viewcontroller and then I want to pop my previous pushed controller Here is my navigation flow From Tabbarviewcontroller 1-

How to create horizontal carousel in iOS 10 Swift 3

只愿长相守 提交于 2021-01-20 18:08:30
问题 Recently I have switched to iOS from Android world. I have seen two options for creating horizontal sliders. My goal is to create an horizontal slider of cards present on this image. I got confused which element need to the best option in iOS. Should I use CollectionView for this OR should I use PageViewController for this? Since I am beginner I cannot use library at this stage with limited knowledge I have. Please suggest me how should I do it 回答1: Short answer You should use a

Pass the instance as a reference to another class in swift

徘徊边缘 提交于 2021-01-06 04:34:39
问题 Swift newbie here, I'm trying to pass the instance of a class to another class yet the editor keeps marking it as a mistake, this is the code i have: ViewController.swift import UIKit import Foundation class ViewController: UIViewController { let handler: Handler = Handler(controller: self) override func viewDidLoad() { super.viewDidLoad() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } } Handler.swift import Foundation class Handler { var controller:

Swift3 : Hide UITableView if Empty

家住魔仙堡 提交于 2021-01-03 08:02:20
问题 I have a tableview, which I use as a part of the screen. @IBOutlet var tableView: UITableView! Sometimes I have data, and sometimes I don't. I want to display the table only when data is present and hide it when there is no data. I tried adding a constraint of height with lesser or equal to options. But if I do that, tableview is hidden even when I have data what should I do? I googled around and didn't find a solution, so asking here. Disclaimer: I am new to iOS/Swift development. Sorry if

Swift3 : Hide UITableView if Empty

无人久伴 提交于 2021-01-03 08:00:06
问题 I have a tableview, which I use as a part of the screen. @IBOutlet var tableView: UITableView! Sometimes I have data, and sometimes I don't. I want to display the table only when data is present and hide it when there is no data. I tried adding a constraint of height with lesser or equal to options. But if I do that, tableview is hidden even when I have data what should I do? I googled around and didn't find a solution, so asking here. Disclaimer: I am new to iOS/Swift development. Sorry if