Tag: swift

在UITableViewCell中使用UITextViewdynamic调整单元大小会导致警告?

目前在我的代码中,我以编程方式在UITableViewCell添加一个UITextView ,并添加了根据用户键入的内容大小自动调整单元格的function。 目前看起来像这样: override func viewDidLoad() { tableView.estimatedRowHeight = 30.0 tableView.rowHeight = UITableViewAutomaticDimension } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { // Dequeue the cell to load data let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) if indexPath.section == 0 { // Code } if indexPath.section == 1 { let textView: […]

使用AVAudioPlayer播放多个audio文件

我在主StoryBoard上创build了3个UIButtons。 当我按下“button1”或“button2”时,每个播放audio文件(“播放器1”,“播放器2”)。当audio播放时,UIButton被设置为selected 。 我想“Button3”在一行中实现多个函数。 这意味着当我按下“button3”时,应该首先播放“播放器3”,然后在“播放器1”之后播放“播放器2”。 然而,当我按下“Button3”时,同时播放“播放器1”和“播放器2”,因为前一个结束没有延迟。 我发现设置AVAudioPlayer的代理或使用AVQueuePlayer将解决这个问题,但是我发现很难做出改变。 fileprivate var player1:AVAudioPlayer? fileprivate var player2:AVAudioPlayer? fileprivate var player3:AVAudioPlayer? @IBAction func pushButton1(sender: UIButton) { audioPlayer1(url: url1) } @IBAction func pushButton2(sender: UIButton) { audioPlayer2(url: url2) } @IBAction func pushButton3(_ sender: UIButton) { audioPlayer3(url: url1, url2: url2, url3: url3) } func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) { if (player […]

为什么不UIImagePickerController委托给我的对象类?

class CameraPicker: NSObject, UIImagePickerControllerDelegate, UINavigationControllerDelegate { weak var viewController:MyProfileVC! func launchCamera() { if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) { let imagePicker:UIImagePickerController = UIImagePickerController() imagePicker.delegate = self imagePicker.sourceType = UIImagePickerControllerSourceType.camera imagePicker.cameraDevice = UIImagePickerControllerCameraDevice.front imagePicker.cameraCaptureMode = .photo imagePicker.allowsEditing = false self.viewController.present(imagePicker, animated: true, completion: nil) } } } func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { print("didFinishPickingMedia") } 这是我的对象类函数,但didFinishPickingMediaWithInfo函数拍摄后不会被调用。 […]

将数据从TableViewController传递到XIB文件没有Segues Swift 3

我新来快速学习3 我试图从表视图控制器传递数据到XIB文件。 我有我的表视图控制器中的水果列表。 点击,我想在新的XIB控制器中的标签显示水果名称。 我试过下面的代码,但它没有显示我在XIB vc的任何数据。请告诉我什么,我在这里失踪 我的表VC: class FruitsTableViewController: UITableViewController { var fruits = ["Apple", "Apricot", "Banana", "Blueberry", "Cantaloupe", "Cherry", "Clementine", "Coconut", "Cranberry", "Fig", "Grape", "Grapefruit", "Kiwi fruit", "Lemon", "Lime", "Lychee", "Mandarine", "Mango", "Melon", "Nectarine", "Olive", "Orange", "Papaya", "Peach", "Pear", "Pineapple", "Raspberry", "Strawberry"] override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return […]

search结果中的3D Peek&Pop

我使用search栏来过滤我的表格视图。 我在显示可search内容的相同视图控制器中显示search结果。 它工作正常。 除了一件事 – 3D Peek和Pop不适用于search结果 。 我曾尝试Storyboard segue中的“Peek&Pop”checkbox。 我没有尝试在我的TableViewController中编程偷看和stream行。 结果是一样的:peek&pop适用于表格视图单元格,但不适用于search结果单元格。 这里是search和偷看&stream行代码片断: // Add a search bar searchController = UISearchController(searchResultsController: nil) tableView.tableHeaderView = searchController.searchBar searchController.searchResultsUpdater = self searchController.hidesNavigationBarDuringPresentation = false searchController.dimsBackgroundDuringPresentation = false self.tableView.contentOffset = CGPoint(x: 0, y: searchController.searchBar.frame.height) // Register for preview if traitCollection.forceTouchCapability == .available { previewingContext = registerForPreviewing(with: self, sourceView: tableView) […]

更改variables时更新UILabel文本

我有一个UIControl类,需要根据UIImageView位置进行一些计算,这个位置可以通过touchesBegan和touchesMoved(这个类中的所有东西)来移动。 比我想显示它作为我已经编程创build的UILabel。 class control : UIControl{ … let leftControl: UIImageView = UIImageView(image: UIImage(named: "left-control")) … func leftValue() -> String{ var leftValue : String = "0.0" leftValue = "\(leftControl.center.x)" return leftValue } } 和我的ViewController.swift class ViewController:UIViewController { let ctrl : Control = Control() let leftLabel : UILabel = UILabel(frame: CGRect(x: 40, y: 300, width: 150, height: […]

Swift计算UITextFields的值并返回值

使用swift和Xcode 6,我试图返回基于less数UITextFields的内容计算的值。 我已经声明variables var Number1 = Field1.text.toInt() var Number2 = Field2.text.toInt() var Duration = Number1*Number2 Mylabel.text = String ("\(Duration)") 这个想法是从几个UI字段中获取持续时间,并基于这些值的计算将其分配给一个variables,并将其显示在标签上。 在行中:var Duration = Number1 * Number2 挑战是我的是当执行乘法Xcode突出显示错误:可选types'Int?'的值 不解开; 你的意思是使用'!' 要么 '?'?

Swift UIWebView shouldStartLoadWithRequest在iOS8中不会触发

我有一个UIWebView,预期会在作为初始页面加载的login页面成功login后返回一个自定义URL。 自定义url是appevent:// 除了iOS8.X(即iOS9.X及以上版本)以外, 笔记详细 使用webview委托方法' shouldStartLoadWithRequest '。 初始URL正常加载,用户input用户名和密码。 在一个成功的事件中,webview javascript给了后面的window.location.href appevent://{"something"} 使用下面的代码,我进一步处理我收到的数据appevent public func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool { let urlScheme = request.URL?.scheme if urlScheme == "appevent" { let urlString = request.URL!.absoluteString! let startIndex = urlString.rangeOfString("appevent://", options: .BackwardsSearch)?.endIndex let payload = (urlString.substringFromIndex(startIndex!)) .stringByReplacingPercentEscapesUsingEncoding(NSWindowsCP1252StringEncoding)! handleAppEvent(payload) return false } return true } […]

swift PUT API调用缺less参数

我继续得到一个错误代码400:缺less参数我相信问题是我发送数据的格式 API DOC: http : //middleware.idxbroker.com/docs/api/methods/index.html#api-Leads-putLead 我相信所需的数据需要的是名字,姓氏和电子邮件,我是否需要发送其他领域为零或我可以让他们空白? API调用 /// Send Lead to IDX Broker /// /// – Parameter lead: new Lead data fields /// – Returns: configs for URL Session class func putLead(lead: String) -> URLRequest { let urlString = "https://api.idxbroker.com/leads/lead" let url = NSURL(string: urlString) var downloadTask = URLRequest(url: (url as URL?)!, cachePolicy: URLRequest.CachePolicy.reloadIgnoringCacheData, […]

无法使用Delegate更新UITableViewCell中的标签

我在我的应用程序中有一个食物日记,用于跟踪您每天所吃的食物,但是我正在努力更新我的UITableViewCell卡路里标签。 我的应用程序崩溃,只要按“保存到食物日记”,错误是: "fatal error: unexpectedly found nil while unwrapping an Optional value" 这里是我在我的PopUpVC ( UIViewController ,用户可以看到inputFoodName和Calories ) protocol AddRowDelegate { func didAddRow(name : String, calories : String) } class PopupVC: UIViewController { var delegate: AddRowDelegate? var section: Int? var caloriesLabel = " " var tableData: [String] = [""] var caloriesCell = caloriesForDiary() @IBOutlet weak var […]