Tag: swift

为什么Objective-C API返回隐含的解包选项?

我对此感到困惑。 如果我们以UITableView的方法cellForRowAtIndexPath:为例,它的方法签名是: func cellForRowAtIndexPath(_ indexPath: NSIndexPath!) -> UITableViewCell! 其回报值是: 表示单元格的对象,或者如果单元格不可见或indexPath超出范围,则为nil。 这听起来像是使用标准可选的完美理由。 实际上,由于Objective-C中所有基于指针的types都可以是零,所以所有的Objective-C指针types都应该作为标准选项来导入。 我从WWDC的谈话中知道,他们认为,对于隐含的解包选项: 可以明确地testing为零 可以直接访问底层值的属性/方法 可以隐式转换为其基础值 从Apple的Cocoa和Objective-C中使用Swift, 当您访问这种types的可选types的值时,如果不安全地解包它,隐式解包的可选操作将检查值是否丢失。 如果缺less该值,则会发生运行时错误。 所以,他们决定把它作为一个声明,说它永远不应该是零,但可能是一个可选项,而不是将一个可能的零值导入到Swift中。 这听起来像是他们完全否定了Swift中Objective-C API的可选types的安全性。 我似乎错过了什么? 他们没有给出编译时间错误或警告,而是认为运行时错误更好? 这很混乱。 考虑到似乎没有任何东西可以回答我所看到的这个问题……我认为这是其他人显而易见的,我只是没有看到,而是……为什么这样呢? 是否真的只是为了避免人们在Swift中使用Objective-C API时使用或不使用链接,或者更多?

如何在input(Swift)时进行实时UITextField计数?

我想在用户继续用swiftinputUITextField时计算字符。 字段和标签的图像: 我已经放置了UITextField和UILabel,只是没有发现任何关于堆栈溢出的信息,如果你可以在UITextView中做一个,我也很感激。

tableView节标题消失SWIFT

我有一个tableView设置,以便当一个单元格被触摸,它的高度展开,以显示更多的信息。 tableView有5个部分。 我有一个错误:当一个单元格展开时,该单元格下的所有headersCells不可见。 控制台输出如下内容:“[31233:564745]表格单元格重新使用没有索引path” 在我的故事板中,我有2个自定义单元格:数据承载单元格为“myCell”,标题为“headerCell”。 func tableView(tableView:UITableView,didSelectRowAtIndexPath indexPath:NSIndexPath){ let thisGoal : GoalModel = goalArray[indexPath.section][indexPath.row] if self.currentPath != nil && self.currentPath == indexPath { self.currentPath = nil } else { self.currentPath = indexPath } tableView.beginUpdates() tableView.endUpdates() } 如果我在开始/结束更新之间inputtableView.reloadData(),它将正常运行,但标题背景变黑,并且会丢失animation。 我有所有的声明在头文件的东西:func tableView(tableView:UITableView,viewForHeaderInSection部分:INT) – > UIView? 我错过了什么? 我真的很喜欢tableView仍然有animation,并保持clearColor()的背景。 提前致谢。 我确实读了客观的答案,但无法让他们为我工作。 我非常感谢SWIFT的帮助。 我认为问题是表单元格被重用的no索引path。

UICollectionReusableView – 缺less函数返回

考虑到UICollectionView的头部,我有一个奇怪的问题。 我基本上使用的代码: http : //www.raywenderlich.com/78551/beginning-ios-collection-views-swift-part-2 func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView { let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "dd.MM.yyyy' – 'HH:mm'" //1 switch kind { //2 case UICollectionElementKindSectionHeader: //3 let h = collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: "eventHeaderView", forIndexPath: indexPath) as eventHeader h.eventFirstline.text = "First Line" h.eventSecondline.text = thisEvent.eventName h.eventDate.text = dateFormatter.stringFromDate(thisEvent.startDate) h.eventDescription.text […]

popup不在button上

我正在尝试将一个popup窗口放在一个button上。 我似乎无法弄清楚我可能会出错的地方。 而不是button中间的箭头,它是偏离屏幕宽度的一半。 @IBAction func buttonClicked(sender: AnyObject){ var popoverViewController = self.storyboard?.instantiateViewControllerWithIdentifier("ServiceOptions") as! ServiceOptionsPopover popoverViewController.delegate = self popoverViewController.modalPresentationStyle = .Popover popoverViewController.preferredContentSize = CGSizeMake(300, 300) let popoverPresentationViewController = popoverViewController.popoverPresentationController popoverPresentationViewController?.permittedArrowDirections = .Up popoverPresentationViewController?.delegate = self popoverPresentationViewController?.sourceView = sender as! UIButton popoverPresentationViewController?.sourceRect = sender.frame presentViewController(popoverViewController, animated: true, completion: nil) }

如何使用cocoapods安装Facebook的SDK的iOS?

在Facebook的文档:这里: https : //developers.facebook.com/docs/ios/getting-started 这是写我们可以使用: pod \'Facebook-iOS-SDK\' 在我们的项目中安装pod。 但是我将它添加到第10行的pod文件中,并尝试运行pod install,它在terminal上显示以下错误: [!] Oh no, an error occurred. It appears to have originated from your Podfile at line 10. Search for existing github issues similar to yours: https://github.com/CocoaPods/CocoaPods/search?q=%2FUsers%2Fprajeetshrestha%2FDesktop%2FHotRents%2FPodfile%3A10%3A+syntax+error%2C+unexpected+%24undefined%0A++++pod+%5C%27%2FUsers%2Fprajeetshrestha%2FDeskt…%0A+++++++++%5E%0A%2FUsers%2Fprajeetshrestha%2FDesktop%2FHotRents%2FPodfile%3A13%3A+syntax+error%2C+unexpected+tCONSTANT%2C+expecting+keyword_end%0Atarget+%27HotRentsTests%27+do%0A+++++++++++++++++++++%5E%0A%2FUsers%2Fprajeetshrestha%2FDesktop%2FHotRents%2FPodfile%3A13%3A+unterminated+string+meets+end+of+file%0A%2FUsers%2Fprajeetshrestha%2FDesktop%2FHotRents%2FPodfile%3A13%3A+syntax+error%2C+unexpected+end-of-input%2C+expecting+keyword_end&type=Issues If none exists, create a ticket, with the template displayed above, on: https://github.com/CocoaPods/CocoaPods/issues/new

Facebook的login总是回来取消。 (iOS Swift)

我目前正在尝试使用4.0版本的SDK实现Facebooklogin,这也发生在3. +版本。 当我调用logInWithReadPermissions (4.0版本)或openActiveSessionWithReadPermissions (3. +版本)。 在用户可以进行select( 取消或确定 )之前,立即使用isCancelled (4.0版本)和ClosedFailedLogin (3. +版本)调用闭包/块。 我认为这可能是在我的plist设置的URL计划的问题,但我已经检查了一遍又一遍,一切似乎是正确的。 只是想知道如果有人可以有任何解决这个问题的想法。 我的Bundle ID是正确的,在Facebook开发控制台中启用了单点login,本地应用程序已启用。 请参阅下面的一些示例代码和configuration(4.0版本)。 login电话: AppDelegate中: plist中:

iOS自定义状态栏背景颜色不显示

我正在尝试使用以下方式将状态栏背景颜色填充为橙色 UINavigationBar.appearance().tintColor = UIColor.orangeColor() UINavigationBar.appearance().barTintColor = UIColor.orangeColor() UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()] UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.LightContent, animated: true) 但是,我得到一个白色的状态栏,应该填充橙色,而不是以下示例: 使用swift自定义导航栏外观 我将其设置在didFinishLaunchingWithOptions方法下的AppDelegate.swift文件中,以将其应用于整个应用程序。 我已经编辑了我的info.plist到以下内容: View controller-based status bar appearance => NO 有谁知道我在做什么错? 编辑:我不知道是否重要,但视图是在UITabBarController 编辑2:这实际上发生在所有的意见,而不仅仅是UITabBarController 。 编辑3:谢谢@Utsav Parikh 我现在在状态栏的顶部添加一个视图,在应用程序加载状态栏的时候,它是一个短暂的时间,但是一旦它完成加载,它将被closures视图,并replace为通用的白色状态栏。 为什么会这样呢? let view = UIView(frame: CGRect(x: 0.0, y: 0.0, width: UIScreen.mainScreen().bounds.size.width, height: 20.0)) view.backgroundColor=UIColor.orangeColor() self.window!.rootViewController!.view.addSubview(view) 编辑Swift 3 : 与UITabBarController let view = UIView(frame: […]

Swift 3.0中的NSIndexPath和IndexPath

我最近把我的代码转换成了Swift 3.0。 我的集合视图和表视图数据源方法现在在它们的方法签名中包含IndexPath而不是NSIndexPath 。 但是在方法定义里面仍然是对NSIndexPathtypes转换IndexPath。 即 func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell : NNAmenitiesOrFurnishingCollectionViewCell = self.amenitiesOrFurnishingCollectionView.dequeueReusableCell(withReuseIdentifier: "NNAmenitiesOrFurnishingCollectionViewCell", for: indexPath) as! NNAmenitiesOrFurnishingCollectionViewCell cell.facilityImageName = self.facilityArray[(indexPath as NSIndexPath).row].imageName cell.facilityLabelString = self.facilityArray[(indexPath as NSIndexPath).row].labelText return cell } 任何人都可以告诉我为什么indexPathtypes转换为NSIndexPath 。

FBSDK(新Facebook SDK 4.0)实施不适用于使用Facebooklogin

我正在使用Facebook Developer中提到的下面的块。 但是,当我的应用程序从浏览器callback,那么它总是返回取消结果。 FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; [login logInWithReadPermissions:@[@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) { if (error) { // Process error } else if (result.isCancelled) { // Handle cancellations } else { // If you ask for multiple permissions at once, you // should check if specific permissions missing if ([result.grantedPermissions containsObject:@"email"]) { // […]