Tag: swift

如何通过Segue传递variables从一个子类到一个SecondViewController

我有一个名为“资本”,声明variables的子类,我想推动这些variables通过子类通过一个新的SecondViewController 除了“资本”的子类,我还有(2)ViewControllers:ViewController – > SecondViewController 这是我的代码为“资本”的子类 import MapKit import UIKit class Capital: NSObject, MKAnnotation { var title: String? var coordinate: CLLocationCoordinate2D var info: String var imageForAnnotationView: UIImage? { guard let title = title else { return nil } return UIImage(named: "\(title).png") } init(title: String, coordinate: CLLocationCoordinate2D, info: String) { self.title = title self.coordinate = coordinate […]

在signUpInBackgroundWithBlock期间将configuration文件图像上传到parse.com时遇到问题

我正在使用下面的代码注册一个用户名,密码和个人资料图片。 func createUserwithAllFields() { let profileImageData = UIImageJPEGRepresentation(profileAvatar.image, 0.6) //let profileImageData = UIImageJPEGRepresentation(profileImg, 0.6) let profileImageFile = PFFile(data: profileImageData) if tv_username.text != "" && tv_password.text != "" { var user = PFUser() user.username = tv_username.text user.password = tv_password.text user["profileImage"] = profileImageFile user.signUpInBackgroundWithBlock({ (success, error) -> Void in if error == nil { //if SignUp is […]

方法被调用,但不能正确执行

我已经从CollectionViewController – > MenuTableViewController – > ListViewController成功链接链接的委托方法。 在ListViewController扩展中,我调用changeTitleView()但它不工作。 数据,但是成功通过,因为print(title)正确打印传递的信息。 如果在ListViewController调用, changeTitle()正确执行 class ListViewController { var navigationTitle: String? @objc func changeTitle(title: String) { let titleLabel = UILabel() let attributes: NSDictionary = [ NSAttributedStringKey.font:UIFont(name: "HelveticaNeue", size: 20)!, NSAttributedStringKey.foregroundColor: UIColor(red: 0.1137, green: 0.1137, blue: 0.149, alpha: 0.8) /* #1d1d26 */, NSAttributedStringKey.kern:CGFloat(2.0) ] let attributedTitle = NSAttributedString(string: title.uppercased(), attributes: […]

如果通知已打开,如何直接进入特定的视图控制器

我有一个UITabBarController在一个选项卡中显示聊天表。 如果用户点击一行,将显示一个视图控制器,显示最新的消息。 现在我正在介绍推送通知。 如果用户打开推送通知,所需的行为是自动进入聊天室。 虽然有关于如何处理这些用例的大量信息,但是我没有成功实现它。 这是我的代码到目前为止: func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. if (!isUserLoggedIn()) { // show login vc } else { let protectedController = mainStoryboard.instantiateViewController(withIdentifier: "TabBarController") as! UITabBarController if let notificationPayload = launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification] as? NSDictionary { if let chatId = notificationPayload["chatId"] […]

在UITableView上正确显示边框

我正在试图通过显示一个边框来修饰我的tableview。 这是目前的样子: 一切都很好,期待下半部分。 我希望边框位于最后一个显示单元的分隔符的底部。 这是没有边界时的样子: 我正在使用这样的页脚,并添加像这样的边框: self.tableView.tableFooterView = UIView() self.tableView.backgroundColor = UIColor.clearColor() tableView.layer.masksToBounds = true tableView.layer.borderWidth = 2.0 注意 另外一件事,我忘了提及想想。 我想根据有多less个单元来放置边界的高度。 是的,我将永远有相同数量的细胞,但在不同的屏幕上,并不是所有的细胞都会显示。

如何在Swift中使用Alamofire将发送数组的字典(JSON格式)发送到服务器3

我试图创build和发送字典JSON格式的数组Alamofire。 { "attendance": [{ "attndid":"0", "psngrtype": "student", "date":currentdate, "cuid": "25", "enttid": "21", }] } 在这里,我使用了tableview,在上面的“cuid”&“enttid”中我给出了可选的tableview单元格数据的值。 剩下的是不变的。 我传递一个字典数组,如果我select一个tableview单元格数据。 和两个数组,如果我select两个cells.etc ..和我使用下面的代码,我得到但得到问题创build字典格式。 我的代码: let arrayOfDictionaries: [[String:AnyObject]] = [ ["psngrtype":"student" as AnyObject, "attndid": "0" as AnyObject , "cuid":stdpasngerid as AnyObject, "enttid": entitID as AnyObject, "attnddate":CurrentDate as AnyObject ]] print(arrayOfDictionaries.toJSONString()) extension Collection where Iterator.Element == [String:AnyObject] { func toJSONString(options: JSONSerialization.WritingOptions […]

强制方向在iOS 10设备中不起作用

目前,我正在做AVPlayer全屏button按下时强制方向的变化。我尝试了类似的东西 final class NewMoviePlayerViewController: AVPlayerViewController { override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() if contentOverlayView?.bounds == UIScreen.main.bounds{ DispatchQueue.main.async { let value = UIInterfaceOrientation.landscapeRight.rawValue UIDevice.current.setValue(value, forKey: "orientation") } print("full screen") }else{ DispatchQueue.main.async { let value = UIInterfaceOrientation.portrait.rawValue UIDevice.current.setValue(value, forKey: "orientation") } print("half screen") } } } 上面的代码在iOS 11中工作正常,但相同的代码不工作在iOS 10和以下版本

集合视图单元格不显示在集合视图中?

我使用纯粹的故事板界面构build器创build了一个集合视图。 这是故事板的样子: 我的collections视图的属性也是默认的。 我还没有写任何东西到我的ViewController.swift 。 出于某种原因,当我在我的手机/模拟器上运行,没有任何button显示。

奇怪的问题:UITableViewCell不会检测到触摸,虽然它是配件视图

我有一个非常简单的UITableView与UITableViewCell中。 DataSource和Delegates被正确设置。 它显示正确的数据。 但是tableview的单元格不响应触摸。 虽然细胞的辅助视图确实响应触摸 。 我尝试为单元格和单元格的辅助视图创buildsegues。 只有连接到附件视图的segue才能正常工作。 ( didSelectRowAtIndexpath方法也不会被调用) 可能是什么原因,以及如何debugging这样的问题?

在Parse的TableviewCell中添加新的第一个Up行?

我遇到了一个问题,parsing.Hochu,以便当添加一个新的行是第一个。 它继续添加到我的最后一行。 我已经提出了一个问题,并尝试了所有的select。 这是我的代码。 请告诉我我做错了什么? 我真的需要一个滑石答复。 段控制 – 当段切换时更新: @IBAction func btnSegment(_ sender: Any) { tableView.reloadData() } 首先添加一个新的行不起作用: func insertRow() { self.soccerString.insert(Soccer(), at: 0) tableView.insertRows(at: [IndexPath(row:0, section: 0)], with: .automatic) } parsing: @objc func loadObjects1() { let query = Soccer.query() as! PFQuery<Soccer> query.findObjectsInBackground { (objects, error) in if error == nil { self.soccerString = objects! […]