Tag: swift3

Swift错误无法转换types的值(AFHTTPRequestOperation?,AnyObject?) – >()

我更新xcode版本8.0(8A218a)swift 3后,我得到了这个错误 无法将types'(AFHTTPRequestOperation?,AnyObject?) – >()'的值转换为期望的参数types'((AFHTTPRequestOperation?,Any?) – > Void)!' 这是上面显示的错误的以下代码。 jsonmanager.post( "http://myapi.com", parameters: nil, success: { (operation: AFHTTPRequestOperation!,responseObject: AnyObject!) in if(responseObject.object(forKey: "meta")?.object(forKey: "status")?.intValue == 200){…. 难道我做错了什么 ? 它在以前的版本7.3.1 swift 2中运行良好。

iPad的模拟器罚款,但iPad上传图片时使用WKWebview崩溃的应用程序

背景和简短摘要 我正在使用WkWebview为了显示我的应用程序的网页。 我拥有它,以便您可以从相机或照片库中select一个图像。 但是,在select图像时,应用程序崩溃似乎存在问题。 眼镜 我在平板电脑上运行IOS 10.0.2,在模拟器上使用Swift 3运行IOS 10.0。我从XCode 8运行。 在模拟器上,当我尝试上传图片时,出现“错误” 我收到以下消息: 2016-10-19 02:15:36.150670 z4[31561:14708540] [Generic] Creating an image format with an unknown type is an error 图像是好的,我可以用它来上传。 我认为这种行为很奇怪,但是我读到它与IOS上的内存pipe理有关 在平板电脑本身,我得到以下 Terminating app due to uncaught exception 'NSGenericException', reason: 'Your application has presented a UIAlertController (<UIAlertController: 0x151e80350>) of style UIAlertControllerStyleActionSheet. The modalPresentationStyle of a UIAlertController with […]

Swift:Tableview在导航栏下滚动,但在状态栏之上?

我用下面的技巧隐藏了导航栏的阴影: self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default) self.navigationController?.navigationBar.shadowImage = UIImage() 我也有以下设置: self.extendedLayoutIncludesOpaqueBars = true self.automaticallyAdjustsScrollViewInsets = true self.tabBarController?.tabBar.isHidden = true 在我的页面上,一切看起来都不错,除了当我滚动我的tableView它按预期在导航栏下,但在状态栏上方: 我如何确保tableView在导航栏和状态栏下滚动?

第一次点击后,UIButton不可点击

我试图从button被点击时从底部带来一个子视图。 但只有第一次button是可点击的。 在animationbutton不可点击后再次点击。 这是代码。 class AnimateView: UIView { var button: UIButton! var menuView: UIView! var mainView: UIView! override init(frame: CGRect) { super.init(frame: frame) mainView = UIView(frame: CGRect(x: 0, y: 0, width: self.frame.size.width, height: self.frame.size.height)) mainView.clipsToBounds = true mainView.backgroundColor = .clear mainView.isUserInteractionEnabled = true mainView.isExclusiveTouch = true self.addSubview(mainView) let theRect = CGRect(x: self.frame.size.width / 2 – […]

添加新的ViewController的视图作为子视图

我正在尝试以下,未能添加新的viewcontrollers视图。 是否只能呈现视图控制器? 我们不能添加视图从其他故事板viewcontrollers视图? //Working let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "customView") as! CustomViewController self.present( viewcontroller , animated: true, completion: nil) //Not working let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "customView") as! CustomViewController vc.view.frame = self.view.frame self.view.addSubview(vc.view)

查看与多个DispatchQueue.main.async使用冻结

当数据被提取并显示时, 查看冻结 。 在我的理解fetchBoard()和initUserInfo()不是并行执行。 (因为view只在fetchBoard()加载板子时加载)我担心多次使用DispatchQueue.main.async会冻结视图。 另外,我如何使它工作顺利。 class MultipleCardsController2vs2: BaseController, UICollectionViewDataSource , UICollectionViewDelegate { override func viewDidLoad() { super.viewDidLoad() let repo = GameRepository() repo.CreateGame(gameID : self.jsonGame.Id , completion: { (jsonGame, err) -> Void in if(err == ErrorCode.NoError){ DispatchQueue.main.async{ self.jsonGame = jsonGame } } }) //These are the two functions I want these 2 to work in […]

Swift 3:如何反转一个透明的导航栏?

我试图创build一个叽叽喳喳的应用程序,模拟真正的应用程序,使用twitter API。 在时间轴视图中,我有一个常规导航栏,当用户点击用户configuration文件时,configuration文件视图具有一个透明栏,以便显示用户的标题图像。 我用下面的代码在导航栏在用户configuration文件视图中是透明的: self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default) self.navigationController?.navigationBar.shadowImage = UIImage() self.navigationController?.navigationBar.isTranslucent = true 我遇到的问题是当我从configuration文件视图返回,时间轴导航栏已成为混乱(下面的截图)。 我猜这是因为我改变了视图控制器中的导航栏的一些方面的configuration文件视图,当我回到时间轴视图结转。 我怎样才能扭转导航栏的透明度,以解决这个不稳定的导航栏? 在时间轴视图控制器中我尝试使用下面的代码来尝试将其反转,但它不起作用。 self.navigationController?.navigationBar.setBackgroundImage(nil, for: .default) self.navigationController?.navigationBar.shadowImage = nil self.navigationController?.navigationBar.isTranslucent = false 带有定期导航栏的时间轴视图 configuration文件视图与透明的导航栏 从configuration文件视图返回后,用随机的导航栏的时间轴视图

带有Alamofire 4数据的POST请求

怎么可能用Alamofire 4发送POST请求与HTTP正文中的数据? 我使用自定义编码在迅速2.3它工作良好。 我转换我的代码swift 3,我试图参数编码,但不工作。 此代码: public struct MyCustomEncoding : ParameterEncoding { private let data: Data init(data: Data) { self.data = data } public func encode(_ urlRequest: URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest { var urlRequest = try urlRequest.asURLRequest() do { urlRequest.httpBody = data urlRequest.setValue("application/json", forHTTPHeaderField: "Content-Type") } catch { throw AFError.parameterEncodingFailed(reason: .jsonEncodingFailed(error: error)) […]

tableView.reloadData()表不更新

该表不显示更新的数组以返回到单元格。 当我启动应用程序,我得到空白单元格。 所有权限已经在故事板中给出。 我试图tableView.reloadData()到处,但似乎无法使其工作。 如果任何人都可以解释我哪里错了,那真的会帮助我好起来。 class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { @IBOutlet weak var slider: UISlider! @IBAction func sliderSelector(_ sender: Any) { tableGenerate() } var arrayTable = [Int]() public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return arrayTable.count } public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell […]

在Swift中使用URLComponents编码“+”

这是我如何添加一个查询参数到一个基本的URL: let baseURL: URL = … let queryParams: [AnyHashable: Any] = … var components = URLComponents(url: baseURL, resolvingAgainstBaseURL: false) components?.queryItems = queryParams.map { URLQueryItem(name: $0, value: "\($1)") } let finalURL = components?.url 如果其中一个值包含+符号,则会出现问题。 出于某种原因,它不会被编码到最终URL中的%2B ,而是保持+ 。 如果我自己编码并通过%2B , NSURL编码% ,'加号'变成%252B 。 问题是我怎么能在NSURL的实例%2B ? PS我知道,我甚至不会有这个问题,如果我自己构造一个查询string,然后只是将结果传递给NSURL的构造函数init?(string:) 。