Tag: 迅速

如何将数据从UIViewController发送到Swift ios中的UITabBarControllers第一个选项卡

首先login屏幕。 login后我收到JSON数据我parsingdata.know我需要将该数据发送到UITabBarControllers第一viewcontroller在该viewcontroller我放置标签。 我需要用这些数据来填写标签 override func prepareForSegue(segue: UIStoryboardSegue,sender:AnyObject!) { if (segue.identifier == "first") { var svc = segue.destinationViewController as Vc1; svc.toPass = name svc.toPass1 = pid svc.toPass2 = sex svc.toPass3 = dob svc.toPass4 = lastvisit svc.toPass5 = height svc.toPass6 = pulse svc.toPass7 = respiration svc.toPass8 = temp svc.toPass9 = sysbp svc.toPass10 = dysbp svc.toPass11 = weight […]

以编程方式调整UIImage的大小不起作用

我试图以编程方式调整图像大小以适应屏幕大小,但是当我构build应用程序时,图像甚至不会显示。 我只是看到一个空白的屏幕,有谁知道我做错了什么? 这是我的代码(从其他一些关于调整图像大小的主题中了解到): class ViewControllerSport: UIViewController { @IBOutlet weak var FotoSport: UIImageView! let screen = UIScreen.mainScreen().bounds override func viewDidLoad() { super.viewDidLoad() FotoSport.frame = CGRect(x: 20, y: 20, width: screen.width * 0.5, height: screen.width * 0.5) FotoSport.image = UIImage(named: "Blokker") }

为什么在Swift中UITableViewCell detailTextLabel是可选的,而textLabel则不是

我想我有点不同“?” 和“!” 用迅捷的语言。 但是在工作的时候,我面对的东西让我更加困惑。 当使用tableview时,我在UITableViewCellfind了以下数据types textLabel和detailTextLabel? 我的问题是:为什么是detailTextLabel? 即使textLabel可能也是可选的?

Lazy init在Swift中的@objc类中的variables

我想在Swift中的类中使用数组的懒惰初始化。 当我为类使用@objc声明时,为了在objective-c中使用它,我得到了一个编译错误。 当我只使用没有@objc的类,我可以编译它没有任何问题。 我得到这个错误: @objc class MyClass { @lazy var arr : String[] = String[]() } 对于下面的代码,我没有得到任何错误: class MyClass { @lazy var arr : String[] = String[]() } 谢谢你的帮助!

video预览期间的屏幕截图失败

我正在尝试使用AVFoundation(AVCaptureDeviceInput和AVCaptureVideoDataOutput)进行video预览时捕获屏幕, 启动预览: func startCamera(){ var screenSize = UIScreen.mainScreen().bounds.size; self.previewView = UIView(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.size.width, UIScreen.mainScreen().bounds.size.height)); self.previewView.contentMode = UIViewContentMode.ScaleAspectFit self.view.addSubview(previewView); session.sessionPreset = AVCaptureSessionPresetHigh let devices = AVCaptureDevice.devices(); // Loop through all the capture devices on this phone for device in devices { // Make sure this particular device supports video if (device.hasMediaType(AVMediaTypeVideo)) { // Finally check […]

捕获Swift中的闭包值

我的问题与其他几个人非常相似,但我无法完成工作。 我正在通过我写的帮助器类进行API调用。 首先,我尝试了一个带有返回值的标准函数,结果如预期的那样。 我厌倦了分配结果后完成了后台任务。 现在我正在使用闭包,我可以将值返回到我的视图控制器,但它仍然在闭合,我有同样的问题。 我知道我需要使用GCD来完成主队列中的任务。 这是我在我的视图控制器 var artists = [String]() let api = APIController() api.getArtistList("foo fighters") { (thelist) -> Void in if let names = thelist { dispatch_async(dispatch_get_main_queue()) { artists = names print("in the closure: \(artists)") } } } print ("method 1 results: \(artists)") 结果是: method 1 results: [] in the closure: [Foo Fighters […]

无法访问kABPersonNoteProperty

我有下面的代码,从iPhone的联系人数据复制到NSMutableDictionary。 我正在使用可选的绑定在这个答案讨论。 firstName和lastName字段正确地复制(以及电话和电子邮件字段在这里没有显示),但是我从来没有能够访问kABPersonNoteProperty ,也没有看到日志中的println语句。 我试图复制笔记作为string和NSString没有成功。 任何想法可能会导致这个问题? var contactInfoDict:NSMutableDictionary! func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController!, didSelectPerson person: ABRecord!) { self.contactInfoDict = ["firstName":"", "lastName":"", "notes":""] if let firstName:String = ABRecordCopyValue(person, kABPersonFirstNameProperty)?.takeRetainedValue() as? String { contactInfoDict.setObject(firstName, forKey: "firstName") println(firstName) } if let lastName:String = ABRecordCopyValue(person, kABPersonLastNameProperty)?.takeRetainedValue() as? String { contactInfoDict.setObject(lastName, forKey: "lastName") println(lastName) } if let notes:String = ABRecordCopyValue(person, kABPersonNoteProperty)?.takeRetainedValue() as? […]

swift didReceiveRemoteNotification userInfo无法获取值

我使用推送通知,并有这个function: func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) { if let msg = userInfo["msg"] as? NSObject { println(msg) } GCMService.sharedInstance().appDidReceiveMessage(userInfo); NSNotificationCenter.defaultCenter().postNotificationName(messageKey, object: nil, userInfo: userInfo) } 这打印我: {"model":"que","data":{"id":101,"vehicle":{"license_plate":"test","taxi":{"id":1,"logo":"/media/logos/mega_CxRn739.png.75x75_q85_crop.png","name":"Mega","city":"Novi Pazar","country":"Srbija"},"label":"A01"}}} // prettify: { "model": "que", "data": { "id": 101, "vehicle": { "license_plate": "test", "taxi": { "id": 1, "logo": "/media/logos/mega_CxRn739.png.75x75_q85_crop.png", "name": "Mega", "city": "Novi Pazar", "country": […]

连接一个CollectionView到一个ViewController,在连接dataSource-Swift-XCode时出错

我可以连接委托,但是,当连接数据源时,我收到以下错误: 2015-07-13 16:45:17.529 paintApp [4628:168318] – [UIView collectionView:numberOfItemsInSection:]:无法识别的select器发送到实例0x7f8a12651c60 2015-07-13 16:45:17.539 paintApp [4628:168318] *终止应用程序由于未捕获exception'NSInvalidArgumentException',原因:' – [UIView collectionView:numberOfItemsInSection:]:无法识别的select器发送到实例0x7f8a12651c60'*第一个抛出调用堆栈:(0 CoreFoundation 0x0000000107f67b75 exceptionPreprocess + 165 1 libobjc.A.dylib 0x0000000109cf7bb7 objc_exception_throw + 45 2的CoreFoundation 0x0000000107f6ec8d – [NSObject的(NSObject的)doesNotRecognizeSelector:] + 205 3的CoreFoundation 0x0000000107ec66fc ___forwarding_ + 988 4的CoreFoundation 0x0000000107ec6298 _CF_forwarding_prep_0 + 120 5的UIKit 0x00000001090a5286 – [UICollectionViewData _updateItemCounts] + 296 6的UIKit 0x00000001090a7469 – [UICollectionViewData numberOfSections] […]

无法使用types((_) – > _)的参数列表调用filter

我试图按标题过滤。 我得到这个错误 class Incident { var title: String = "" } if sender.text != "" { self.incidents = incidents.filter { $0.title.rangeOfString(sender.text, options: NSStringCompareOptions.CaseInsensitiveSearch) == "hola" } } 有任何想法吗?