Tag: swift

iOS 10问题:即使设置了ContentSize,UIScrollView也不滚动

更新:这是一个iOS 10的问题。 这在iOS 9中仍然可以正常工作。 这很有趣。 我只是把我的“教学项目”(一个“玩具”应用)转换成Swift 3。 它已经在Swift 1.2下工作了几年了。 突然间,我的UIScrollView不滚动,即使当我设置contentSize的方式超过其下限。 这里是相关的代码(displayTags例程是调用一个图像的数组,显示居中,稍微垂直偏移,导致垂直链): /*******************************************************************************************/ /** \brief Displays the tags in the scroll view. \param inTagImageArray the array of tag images to be displayed. */ func displayTags ( inTagImageArray:[UIImage] ) { self.tagDisplayView!.bounds = self.tagDisplayScroller!.bounds if ( inTagImageArray.count > 0 ) // We need to have images to display […]

如何快速从datepicker开始和结束时间?

我想从dateselect从datepicker开始和结束的时间。 这是我的代码 func handleDatePicker(sender: UIDatePicker) { let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd hh:mm:ss" let startOfDay = NSCalendar.currentCalendar().startOfDayForDate(sender.date) let components = NSDateComponents() components.hour = 23 components.minute = 59 components.second = 59 let endOfDay = NSCalendar.currentCalendar().dateByAddingComponents(components, toDate: startOfDay, options: NSCalendarOptions(rawValue: 0)) } 但我越来越像2016-10-12 12:00:00输出 我的问题是如何得到如何得到这样的输出 12-09-2016 00:00:00 AND 12-09-2016 23:59:59

如何初始化自定义tableViewCell里面的UiPickerView?

我想在tableViewCell里面创buildPickerView 。 我使我的自定义单元格符合UIPickerViewDelegate和UIPickerViewDataSource协议。 我从控制器发送数据数组到单元格(我认为这不符合MVC模式,可能你也可以build议我如何解决这个问题?)。 但是当tableview调用dequeueReusableCellWithIdentifier ,细胞会调用pickerView函数。 但是,pickerView函数使用了尚未初始化的pickerData 。 我如何解决这个问题? 下面是我的单元格的代码: class PickerTableViewCell: UITableViewCell, UIPickerViewDelegate, UIPickerViewDataSource { @IBOutlet weak var picker: UIPickerView! @IBOutlet weak var title: UILabel! var pickerData: Array<String>! override func awakeFromNib() { self.picker.delegate = self; self.picker.dataSource = self; super.awakeFromNib() } override func setSelected(selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) // Configure the view […]

如何使用UIApplication和openURL并从foo:// q = string在“string”上调用swift函数?

我想我的swift iOS应用程序调用自定义url的查询函数。 我有这样的urlmyApp://q=string 。 我想启动我的应用程序并调用string函数。 我已经注册了Xcode中的url,我的应用程序通过在Safari地址栏中inputmyApp://来启动。 这是我到目前为止在我的AppDelegate.swift: func application(application: UIApplication!, openURL url: NSURL!, sourceApplication: String!, annotation: AnyObject!) -> Bool { return true } 我如何获得查询string所以我可以调用myfunction(string) ?

Swift NSTimer将用户信息检索为CGPoint

override func touchesBegan(touches: NSSet, withEvent event: UIEvent) { let touch = touches.anyObject() as UITouch let touchLocation = touch.locationInNode(self) timer = NSTimer.scheduledTimerWithTimeInterval(0.5, target: self, selector: "shoot", userInfo: touchLocation, repeats: true) // error 1 } func shoot() { var touchLocation: CGPoint = timer.userInfo // error 2 println("running") } 我正在尝试创build一个计时器,该计时器将周期性地运行,将触摸点(CGPoint)作为userInfo传递给NSTimer,然后在shoot()函数中访问它。 但是,现在我得到一个错误,说 1)调用中的额外参数select器 2)不能转换expression式typesAnyObject? 到CGPoint 现在我似乎无法将userInfo传递给另一个函数,然后检索它。

用swiftparsing当前用户关系

我有一个系统,当当前用户接受请求我的应用程序添加发送请求的用户之间的关系当前用户。 但是我也想把当前用户添加到另一个用户的关系中,以便它不仅仅是当前用户有关系。 我的代码为当前用户工作,但不为其他用户。 //i use this pattern to add the requester to a friends relation to the current user var relation = PFUser.currentUser()!.relationForKey("Friends") relation.addObject(passenger as PFObject) PFUser.currentUser()!.saveInBackground() 当我为乘客尝试相同的模式时,不会添加关系 var relation = passenger.relationForKey("Friends") relation.addObject(PFUser.currentUser()!.self as PFObject) passenger.saveInBackground() 编辑1: 经过大量的研究,我发现这个答案说我需要云代码。 https://stackoverflow.com/a/23305056/3822504这是唯一的方法,还是有一个替代? 有人可以提供云代码解决scheme吗? 编辑2: 我回答了我自己的问题。 您将需要根据您的需要编辑云代码。 帮助我的最重要的事情就是知道如何在云代码中查询用户类,并在云代码中获取当前用户。

表视图数据源不显示所有行

我是一个经验丰富的网站和Android开发人员,并正在使用Swift 2开始iPhone开发的书,教导自己在运行xCode 8.2的MacBook上开发iPhone。我遇到了将本书中的例子转换为Swift 3的问题,但是已经能够处理其中大部分。 但是桌子不太好。 我已经转换了所有可以找出的方法,但是无法将所有表格数据都显示在任何示例上。 这是我的代码: // // RootViewController.swift // Fonts // // Created by Thomas Hehl on 12/21/16. // import UIKit class RootViewController: UITableViewController { private var familyNames: [String]! private var cellPointSize: CGFloat! private var favoritesList: FavoritesList! private static let familyCell = "FamilyName" private static let favoritesCell = "Favorites" override func viewDidLoad() { […]

放松Segue – 在哪里拖出口?

我正在试着了解这个放松的过程是如何工作的。 首先我创build了3个ViewControllers。 GlobalVC -LoginVC -RegisterVC 我将初始页面设置为GlobalVC(只有经过身份validation的用户才能看到)。 我设置了从: GlobalVC to LoginVC称为globalToLogin和LoginVC to RegisterVC称为loginToRegister 。 这是我的故事板: 对于registerToLogin方向,我使用了这个解决方法(在RegisterVC中),但看起来有点难看。 @IBAction func unwindToLogin(sender: AnyObject) { //Dismiss View dismissViewControllerAnimated(true, completion: nil) } 但是,现在我试图从LoginToGlobal直接 首先,我selectloginbutton,将其拖到LoginVC: @IBAction func loginButton(segue: UIStoryboardSegue) { performSegueWithIdentifier("unwindToGlobal", sender: self) } 在设置segue: UIStoryboardSegue ,现在可以右键单击Exit。 但是,我在这里感到困惑。 不pipe我试图把Exit拖到圆圈里面,它会给出一个错误: 由于未捕获exception'NSInvalidArgumentException',终止应用程序'>原因:'接收器(0x7fdd2068a480>)没有标识符'unwindToGlobal'的segue 我应该在哪里拖动圈子? (我不断看到Unwind segue to 'Exit' )

UITextView作为InputAccessoryView直到animation之后才会呈现文本

当第一次显示详细视图控制器时,inputAccessoryView将立即渲染文本,但是当您返回并再次尝试时,文本不会被渲染,直到animation完成。 在此处查看演示项目: https : //github.com/SabatinoMasala/accessoryview-demo/ 如果有人有解决scheme,解释或解决办法,我会很高兴听到!

Swift UIDevice.currentDevice()不编译

我有一个快速的项目,我想要检索设备的名称并显示在UITableViewCell 。 但是当我想调用UIDevice.currentDevice()中 override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 编译器失败: 命令/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc失败,退出代码1 以下生成命令失败: CompileSwift正常的arm64“项目文件夹path”/custom_tableview_controller.swift CompileSwiftSources正常的arm64 com.apple.xcode.tools.swift.compiler(2次失败) 尴尬的是调用UIDevice.currentDevice()在任何其他文件比我的custom_tableview_controller.swift文件正在工作。 附加信息: – Xcode 6.4(6E35b) – debugging