Tag: swift

更新Swift中的徽章计数器

使用以下代码,我可以在应用程序编译后立即在徽章图标中获得(2): func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) { let installation = PFInstallation.currentInstallation() installation.setDeviceTokenFromData(deviceToken) installation.badge = 2 installation.saveInBackground() } 我尝试了下一个变体:初始化一个新的var badgeCount = 0和更高版本: func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) { badgeCount++ let installation = PFInstallation.currentInstallation() installation.setDeviceTokenFromData(deviceToken) installation.badge = badgeCount installation.saveInBackground() } 但是,当我收到新的通知,它不会更新到+1。 有谁知道如何解决它?

属性'self。*'没有在super.init调用中初始化

我只是更新我的xcode到6.3.1。 问题是我得到这个奇怪的错误信息,因为迅速1.2。 我得到了这种错误信息 /Users/MNurdin/Documents/iOS/xxxxx/Library/SideBar.swift:32:15: Property 'self.originView' not initialized at super.init call /Users/MNurdin/Documents/iOS/xxxxx/Library/SideBar.swift:38:20: Immutable value 'self.originView' may only be initialized once 在这个代码上 let originView:UIView? override init() { super.init() //error here } init(sourceView:UIView, menuItems:Array<String>){ super.init() //error here originView = sourceView //error here 请指教。 谢谢。

错误:“expression式的types不明确,没有更多的上下文”

我很新的编码Swift,所以请原谅,如果这个错误是一个简单的答案! 我不断收到一条错误消息,指出“expression式的types不明确,没有更多的上下文”。 var findTimelineData: PFQuery = PFQuery(className: "Sweets") findTimelineData.findObjectsInBackgroundWithBlock { (objects:[AnyObject]?, error:NSError?) -> Void in if error == nil { for object:PFObject in objects! { // —-This is the error line— self.timelineData.addObject(object) } } } 我明白问题是什么,我只是不确定如何解决问题。 我已经看到了有关这个答案的其他问题,但没有关于通过一个AnyObject的数组迭代。 谢谢!

如何更改Swift中多个组件的UIPickerView的文本颜色?

以下代码将更改所有3个组件的选取器视图的字体颜色。 但是,当我试图旋转轮子时,它会崩溃。 我认为这与didSelectRow函数有关。 也许这两个函数必须以某种方式嵌套? 任何想法? func pickerView(pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? { var attributedString: NSAttributedString! if component == 0 { attributedString = NSAttributedString(string: a.text!, attributes: [NSForegroundColorAttributeName : UIColor.redColor()]) } if component == 1 { attributedString = NSAttributedString(string: b.text!, attributes: [NSForegroundColorAttributeName : UIColor.redColor()]) } if component == 2 { attributedString = […]

CLGeocoder返回错误的结果,当城市名称等于某个国家的名称(而不仅是)

在我的一个应用程序中,我需要添加一个按名称查找城市的function。 我正在使用CLGeocoder来实现这一点,我希望它有一个相同的iOS天气应用程序的行为。 下面是我有的代码: CLGeocoder().geocodeAddressString(searchBar.text!, completionHandler:{ (placemarks, error) -> Void in guard let nonNilMarks = placemarks else {return} for placemark in nonNilMarks { print("locality: \(placemark.locality)") print("name: \(placemark.name)") print("country: \(placemark.country)") print("formatted address: \(placemark.addressDictionary)") } }) 它在大多数情况下运作良好。 但是,最近我注意到一些失败的情况。 以下是一些例子的输出: search“米兰” – 作品 locality: Optional("Milan") name: Optional("Milan") country: Optional("Italy") formatted address: Optional([SubAdministrativeArea: Milan, State: Lombardy, CountryCode: IT, Country: Italy, […]

UICollectionViewCell内容在第一次加载时大小错误

我有一个UICollectionView添加到我的UIViewController并为它定制了一个单元格。 我使用sizeForItemAtIndexPath方法设置单元格的大小,并将每个单元格的高度和宽度设置为UIScreen.mainScreen().bounds.width/2 。 所以基本上,每个单元的宽度是屏幕宽度的一半,长度也是相同的。 然后在单元格内部有一个UIImageView ,每个边缘固定在单元格的相对边缘,以便图像视图填充单元格。 我也有一个UILabel在单元格中垂直和水平居中。 然而,在第一次加载时,单元格的尺寸是正确的,但是在左上方的一个小方格中内容要小得多。 (如下图所示,我将单元格的contentView背景颜色设置为绿色,将imageView背景颜色设置为红色)。 然后,向下滚动一下(我假设一个可重用的单元格正在出列),所有的单元格都很好(滚动后保持不变)。 什么是导致内容在第一次加载时不能被正确地约束? UPDATE 我的UIViewController一些代码: func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { var cell = collectionView.dequeueReusableCellWithReuseIdentifier("PrevDrawCell", forIndexPath: indexPath) as? PrevDrawCell if cell == nil { cell = PrevDrawCell() } cell!.drawVC = self cell!.imageShortCode = self.tempImageURLs[indexPath.row] // Pull image (async) and set after download cell!.setupImage() cell!.contentView.backgroundColor […]

当tweet失败时,UIActivityViewController完成处理程序返回成功

我正在使用UIActivityViewController来显示共享表,以便用户可以共享我的应用程序。 我目前正在testing推文,我收到了一些意想不到的结果。 第一次在推特上,一切顺利。 第二次,我得到一个重复的鸣叫错误消息,这是预期的。 问题是completionWithItemsHandler正在返回成功:布尔为真! 我希望能够向用户显示自己的个性化消息,而不是当前返回的大量消息。 这是我的代码: @IBAction func ShareButtonTapped(sender: AnyObject) { let textToShare = "I'm using Buzz! The new way to send emoji's, with sound, it's annoying, funny and amazing" var url = NSURL(string: "-Image url masked out-") var data = NSData(contentsOfURL: url!) let image = UIImage(data: data!) if let myWebsite = NSURL(string: "-redirect […]

Xcode 7.1与iOS 9.2错误(无法find开发者磁盘镜像)

我在我的iPhone 5上安装了iOS 9.2(13C71),并且我作为苹果开发者注册了。 在我的Macbook Pro上,我有XCode 7.1和OSX El Capitan。 当我尝试在手机上运行项目时,出现错误 – “找不到开发者磁盘映像”。 有谁知道什么是错的?

parsing分析自定义事件不注册

这两个命令注册为分析事件,但我看不到自定义事件名称的细分。 PFAnalytics.trackEventInBackground("ML Feeling Bad", block: nil) – var dictionary = ["test" : "val"] PFAnalytics.trackEventInBackground("ML Feeling Good", dimensions: dictionary, block: nil) 我正在查看“分析”>“事件”>“分析请求”。 自定义细分似乎没有任何有用的选项。

在webview页面中使用swift查找文本?

我怎样才能在uiwebview页面中find文本,并突出显示它,并使用swift在页面中的位置? 例如chrome查找文本: search范例 但是我使用alert视图: 我的search例子在我的应用程序!