Tag: swift

返回函数内部无效

我正在尝试创build一个自定义类来点击图片。 在里面,我想创build一个返回一个UIImage的clickPicture函数。 但是, captureStillImageAsynchronously是一个void 。 我怎样才能返回从我收到的图像? 谢谢。 func clickPicture() -> UIImage? { if let videoConnection = stillImageOutput?.connection(withMediaType: AVMediaTypeVideo) { videoConnection.videoOrientation = .portrait stillImageOutput?.captureStillImageAsynchronously(from: videoConnection, completionHandler: { (sampleBuffer, error) -> Void in if sampleBuffer != nil { let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sampleBuffer) let dataProvider = CGDataProvider(data: imageData!) let cgImageRef = CGImage(jpegDataProviderSource: dataProvider!, decode: nil, shouldInterpolate: true, intent: […]

NSUrlSession在Swift中运行缓慢

在迅速,我正在迅速下载数据到我的iOS应用程序。 它工作得很好,尽pipe最终发生的事情是它可能需要长达20秒的时间来加载,即使我正在快速连接。 我不明白为什么会发生这种情况。 我几乎想要在应用程序打开之前下载所有的数据,虽然我不想这样做,因为我知道可以加快速度,我知道这是可能的,因为像YouTube和Facebook这样的应用程序可以加载和刷新小于20秒。 哎呀,YouTube加载video的时间less于这段时间。 我知道我的服务器没有那么快,但是我碰巧知道我的服务器比那更快。 我想提醒你,页面最终不会很快加载。 请帮忙。 这是NSUrlSession代码。 func contactApiUrl(){ let url = "http://www.example.com" let nsUrl = NSURL(string:url) let nsUrlRequest = NSURLRequest(URL: nsUrl!) let task = NSURLSession.sharedSession().dataTaskWithRequest(nsUrlRequest){ (data, response, error) in if let dat = data{ let contents = NSString(data:dat, encoding:NSUTF8StringEncoding) as! String self.aboutText.text = contents } } task.resume() } 我想感谢任何人可以提前帮助我。

UICollectionView单元格与图像,在Swift中点击更改背景

我有一个集合视图,看起来像这样: 蓝色的边框是一个图像。 当我按下它们时,我想让文字和图像变暗。 我发现这个问题是类似的: UICollectionView单元格与图像,点击更改背景 它包含在Objective-C中的这个答案 : 如果你有一个CustomCell,你必须有一个CustomCell.m(实现文件)。 在这个文件中join这个,对我来说是简单的方法: -(void)setHighlighted:(BOOL)highlighted { if (highlighted) { self.layer.opacity = 0.6; // Here what do you want. } else{ self.layer.opacity = 1.0; // Here all change need go back } } 我试图添加到我的自定义UICollectionViewCell像这样: import UIKit class DoubleSoundsCollectionViewCell: UICollectionViewCell { @IBOutlet weak var cellLabel: UILabel! func highlighted(highlighted: Bool) { if (highlighted) […]

SWRevealController包括login页面 – Swift

我无法迅速find合适的解决scheme。 我通过Appcoda实现了一个SWRevealController滑出菜单,其中初始视图控制器必须是一个空视图控制器。 我试图包括一个login页面,但是,如果我使这个初始视图控制器,滑出菜单不再起作用。 我如何实现login页面,同时保持滑出菜单的function?

从parsing中查询图像和文本

所以我创build了一个应用程序,用户可以上传图片和文字。 这些post将显示在UICollectionView我会提供一些代码给你看下面。 所以我的PostsViewController看起来像这样: import UIKit import Parse import Bolts import ActiveLabel extension UILabel { func setSizeFont (sizeFont: CGFloat) { self.font = UIFont(name: self.font.fontName, size: sizeFont)! self.sizeToFit() } } extension NSDate { var timeAgo: String { let minute = 60 let hour = 60 * minute let day = 24 * hour let secondsAgo = Int(NSDate().timeIntervalSinceDate(self)) […]

Swift – 将数组中的值转换为double或float

我有一个数组是string的值(但所有的string是像1.0,2.0等值)。 我试图将这些string转换成双打或浮动,所以我可以将它们加在一起。 我如何迅速做到这一点?

Swift将PFQuery转换为TableView的string数组

我试图查询我的数据库中的所有parsing用户,然后在tableview中显示每个单独的用户在他们自己的单元格。 我已经build立了我的tableview,但我坚持把用户查询保存到可以在tableview中使用的string数组。 我创build了一个loadParseData函数,在后台查找对象,然后将查询的对象追加到string数组中。 不幸的是,我在附加数据的行上给出了一条错误消息。 Implicit user of 'self' in closure; use 'self.' to make capture semantics explicit' Implicit user of 'self' in closure; use 'self.' to make capture semantics explicit'在我看来,这是我build议使用self. 而不是usersArray. 因为这是在一个闭包,但我给了另一个错误,如果我这样运行, *classname* does not have a member named 'append' 这是我的代码: import UIKit class SearchUsersRegistrationViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { var userArray = [String]() @IBOutlet var […]

为什么我的注释没有出现在我的地图视图中?

我创build了一套“IssueLocation”,这是一个符合MKAnnotation协议的类。 为什么我的注释(从API JSON数据构build)没有出现在我的地图视图中? 这里是所有背后的代码: class级代码: class IssueLocation: NSObject, MKAnnotation { var locationName: String var campusName: String var latitude: Double var longitude: Double var coordinate: CLLocationCoordinate2D init(locationName: String, campusName: String, latitude: Double, longitude: Double, coordinate: CLLocationCoordinate2D) { self.locationName = locationName self.campusName = campusName self.latitude = latitude self.longitude = longitude self.coordinate = coordinate super.init() } var subtitle: […]

“命令失败,由于信号:分段错误:11” – 这是什么问题?

我做了一些研究,但仍然不知道是什么导致了我的代码中的这个错误(呃,我知道是什么原因造成的,但我不知道为什么…) 本质上,我从Parse Cloud Code中检索一个数组, results 。 然后我把它发送到ViewController2打印出一个UILabel格式的数组的一部分。 当我这样做,我得到编译器错误。 这真让我困惑! 请注意, result ,我检索的数组包含string和布尔值,这就是为什么我把它AnyObject所以我可以稍后施放特定的部分。 云代码: Parse.Cloud.define("checkAccountStatus", function(request, response) { var results = []; var query = new Parse.Query(Parse.User); query.equalTo("username", request.params.username); query.first({ success: function(getUserData) { if (request.params.operation == 1) { var passwordChanged = getUserData.get("passwordChanged"); var question1 = getUserData.get("question1"); var question2 = getUserData.get("question2"); var question3 = getUserData.get("question3"); results.push(passwordChanged); results.push(question1); […]

导航控制器标题不显示

所以,在这里我基本上有这个布局 但是当我成功构build时,我无法看到导航控制器的标题。 我能做什么?