swift2

Connecting UIButtons by drawing a line

限于喜欢 提交于 2019-12-13 01:25:01
问题 I need to connect those buttons with a line but have issues as you can see on the screenshot. I need the last line to go vertical (green circles). Any suggestions? here is the code: @IBAction func drawButtons (sender: AnyObject) { buttonContainerView.removeFromSuperview() // Clear containerView buttonContainerView = UIView() // Create a new instance let buttonCount = array.count let n = Int(self.view.frame.size.width) / 90 //check how many buttons can fit in the screen let buttonsPerRow = n

Update the data of a TableViewController after add item

人走茶凉 提交于 2019-12-13 00:48:31
问题 I have tableView (A) responsible for listing items CoreData and viewController (B) to add new item. To create a ViewController (B) custom, they chose to use the following Present Modally to use presentation Over Current Context to enable transparent background and be able to apply the blur. From tableView (A) press the button to add a new item, the viewController (B) appears. Add a new item and saved in CoreData The viewController (B) execute self.dismissViewControllerAnimated(true,

How to get rid of blink between switching Tab Bar Item

扶醉桌前 提交于 2019-12-12 22:21:27
问题 In my app I should use a several Tab Bar Item with one Controller. To approach this in my Second and Third Tab Bar Item Controllers I use self.tabBarController?.selectedIndex = 0 . As you can see this solution generates blink effect... It's happens every time when I choose Third Tab Bar Item. How to get rid of this blink? Any help is greatly appreciated! 来源: https://stackoverflow.com/questions/39487531/how-to-get-rid-of-blink-between-switching-tab-bar-item

No such module 'SDWebImage'

偶尔善良 提交于 2019-12-12 19:39:11
问题 I installed SDWebImage using CocoaPods . My podfile was as it is written in the https://github.com/rs/SDWebImage platform :ios, '8.0' use_frameworks! pod 'SDWebImage', '~>3.7' when I import SDWebImage it says No such module 'SDWebImage' my Xcode version is: Version 7.2.1 回答1: Use the new <YourProject>.xcworkspace instead of <YourProject>.xcodeproj . The xcworkspace contains your project and your pods after pod install . 回答2: Just build your project before importing any new pods in your code

Retrieving values from 2D array in JSON string

孤者浪人 提交于 2019-12-12 19:33:18
问题 We fetch some JSON data using a REST protocol like this. jsonResult = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.AllowFragments) Which looks like this: jsonResult: ( { board = "[[\"1:\",\"Y\",\"U\",\"P\"]]"; }) From this we get a game board like so: if let boardContentArray = jsonResult[0]["board"] as NSArray?{ print("boardContentArray: \(boardContentArray)" ) } else { print("board element is not an NSArray") } The boardContentArray looks like this: It i

SWIFT: how to run a function even when user kills the app

落爺英雄遲暮 提交于 2019-12-12 19:16:44
问题 I am using swift 2 and Xcode7 for iOS9. I want to know if I can maintain a function (that checks for something to delete) running "forever" even if the user kills the app? I am deleting contacts from the contact list according to some rules and time. It is running ok, but just with the app opened or in second plan. I want to make this app capable to delete those contacts even when the user kills it. 回答1: You can use background thread when user opens the app. But if the app will be terminated,

'queryForTable' cannot return 'nil' In Swift

人走茶凉 提交于 2019-12-12 18:13:37
问题 I am using PFQueryTableViewController as part of ParseUI to load a table of objects based on the currentUser's geolocation. I have seen several other (older) forum posts (like here) detailing that the queryForTable function should return nil if a value like currentLocation:PFGeoPoint? is nil. Then wait on the background process in viewDidLoad to get the PFGeoPoint and loadObjects() , thus calling the queryForTable function again. I am seeing others say that Swift's ParseUI libraries may not

Swift : Use of unresolved identifier 'json'

允我心安 提交于 2019-12-12 18:00:57
问题 I'm currently developing my first iOS app using Swift 2.0 and Xcode 7.0.1. I'm getting a strange little error that I can't seem to fix: var err: NSError? The original code: //var json = NSJSONSerialization.JSONObjectWithData(data, options: .MutableContainers, error: &err) as? NSDictionary Swift2 rewrite code: do { if let json = try NSJSONSerialization.JSONObjectWithData(data!, options: []) as? NSDictionary { print(json) } } catch { print(error) } Use of unresolved identifier 'json' before

Swift 2 AVAudioSession setCategory extra argument 'error'

两盒软妹~` 提交于 2019-12-12 17:43:37
问题 When I set up to record audio, I get an error. if (session.respondsToSelector("requestRecordPermission:")) { AVAudioSession.sharedInstance().requestRecordPermission({(granted: Bool)-> Void in if granted { print("granted") session.setCategory(AVAudioSessionCategoryPlayAndRecord, error: nil) session.setActive(true, error: nil) self.recorder () } else{ print("not granted") } }) } Why do I get an error for having error: nil ? 回答1: Like this: try! session.setCategory

iOS background mode location update - manager doesn't update in background mode

萝らか妹 提交于 2019-12-12 17:34:20
问题 I just followed http://www.raywenderlich.com/92428/background-modes-ios-swift-tutorial location update part. But manager doesn't print location info in background mode. Then manager print logs to Xcode's console when app enter foreground. Is this code right? import UIKit import CoreLocation @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate { var window: UIWindow? var manager = CLLocationManager() func application(application: UIApplication,