标签: xcode8

Swift 3 - 无法覆盖'imagePickerController'

我的代码:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
    self.image = image
    self.imageStatusLabel.text = "There is a picture"
    self.imageStatusLabel.textColor = UIColor.blue()

    picker.dismiss(animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)

这是错误:

无法覆盖已标记为不可用的'imagePickerController':从iOS 7及更早版本中弃用的API在Swift中不可用

好吧,我试过使用更新的功能:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
    // But no image in the parameters
}
Run Code Online (Sandbox Code Playgroud)

但是,参数中没有图像,我可以得到图像.
我该怎么办?

xcode uiimagepickercontroller swift swift3 xcode8

0
推荐指数
1
解决办法
5143
查看次数

UITableViewController,自定义数据源不显示单元格

我目前有一个UITableViewController,它在init函数中设置一个自定义数据源:

class BookmarkTableViewController: UITableViewController {
  var date: Date

  // MARK: - Init
  init(date: Date, fetchAtLoad: Bool) {
    self.date = date
    super.init(style: .plain)
    self.tableView.dataSource = BookmarkDataSource(date: date)
    self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
  }

// ...
}
Run Code Online (Sandbox Code Playgroud)

自定义数据源如下:

class BookmarkDataSource: NSObject {
  let date: Date

  init(date: Date) {
    self.date = date
    super.init()
  }
}

// MARK: - UITableViewDataSource
extension BookmarkDataSource: UITableViewDataSource {
  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 3
  }

  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell …
Run Code Online (Sandbox Code Playgroud)

uitableview ios swift swift3 xcode8

0
推荐指数
1
解决办法
989
查看次数

如何在iOS 10的xcode 8中创建IBAction

当我使用swift在xcode8中创建IBAction时.它在运行时给出错误.无法识别的选择器发送到UIButton

swift ios10 xcode8

0
推荐指数
1
解决办法
6207
查看次数

是否可以使用Xcode 8在真实设备上运行项目而无需注册Apple的开发人员计划?

它不是每次我们创建一个真正的 Xcode项目,有时我们也需要创建项目用于研发目的.为了测试研发项目,我们有时需要使用真实的设备.但我无法在Xcode 8中的实际设备上运行研发项目,而在Xcode 7或Xcode 8之前的版本我们可以.

有没有办法在没有注册的情况下在真实设备上运行测试项目?

ios xcode8

0
推荐指数
1
解决办法
266
查看次数

dyld:库未加载:@rpath/Realm.framework/Realm目标C框架的Realm错误

我已经安装了Realm Objective C Framework(2.0.3),只需将其拖入我在Xcode 8中创建的项目中.当我第一次在模拟器上尝试时,我得到了典型的dyld错误.

dyld: Library not loaded: @rpath/Realm.framework/Realm
Referenced from: /var/containers/Bundle/Application/89F5987A-F3F0-45F2-9014-6BA662135E00/RelamDemo.app/RelamDemo
Reason: image not found
Run Code Online (Sandbox Code Playgroud)

所以我尝试使用以下建议修复它:https: //github.com/realm/realm-cocoa/issues/1681#issuecomment-120749962

它适用于iOS 10模拟器.

但是当我尝试在设备上运行相同的项目(iOS 10/9.3.2)时,我又遇到了同样的dyld错误.

我已经检查过我在项目中复制了Realm.framework.现在我该如何解决这个问题?

objective-c realm xcode8

0
推荐指数
1
解决办法
1113
查看次数

以编程方式设置UIButton的图像?

我想在特定事件上设置UIButton的图像.这就是我做的:

btn.setImage(UIImage(named: "star"))
Run Code Online (Sandbox Code Playgroud)

ios xcode8 swift3.0.2

0
推荐指数
1
解决办法
8102
查看次数

即使关闭应用程序,如何保持用户登录?我正在使用swift 3和Firebase

我是编码和堆栈溢出的新手,我试图让用户在关闭应用程序后仍然保持登录状态.我也不希望他们总是在屏幕上看到登录.即使关闭应用程序并重新打开应用程序,我该如何保持用户登录.我正在使用Swift 3.0,Xcode 8和Firebase.

import UIKit
import Firebase
import SwiftKeychainWrapper


class LoginViewController: UIViewController {

    @IBOutlet weak var emailField: UITextField!
    @IBOutlet weak var pwField: UITextField!


    override func viewDidLoad() {
        super.viewDidLoad()
        let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(LoginViewController.dismissKeyboard))
        //Uncomment the line below if you want the tap not not interfere and cancel other interactions.
        //tap.cancelsTouchesInView = false

        view.addGestureRecognizer(tap)

        // Do any additional setup after loading the view.
    }


    func dismissKeyboard() {
        //Causes the view (or one of its embedded text fields) to …
Run Code Online (Sandbox Code Playgroud)

ios firebase swift swift3 xcode8

0
推荐指数
1
解决办法
5395
查看次数

在Swift中布局后获取UIScrollView的高度

我有一种情况,我正在使用UIScrollView来帮助使用较小手机的用户查看窗口内的全文.我想要显示一个图像图标,如果他们需要滚动(只是为了让他们知道窗口内有更多)但我在使用Swift找到滚动视图的高度时遇到了问题.

这是我的对象的层次结构

在此输入图像描述

基本上,这4个标签适合4.7"iPhone而不是4"iPhone.我尝试设置一些逻辑来检查UIScrollView内容是否大于窗口,但它似乎没有工作.我一直认为高度为零.

我使用scrollHeight = scrollView.contentSize.height,并试图把那里面viewDidLoad(),viewWillAppear()viewDidLayoutSubviews()但每次它最终被0.

contentSize我应该用它来检查高度是正确的吗?

uiscrollview swift3 xcode8

0
推荐指数
1
解决办法
2836
查看次数

从文档目录而不是文件路径获取图像Swift 3

这就是我保存图像的方式

    let format = DateFormatter()
    format.dateFormat="MMMM-dd-yyyy-ss"
    let currentFileName = "\(format.string(from: Date())).img"
    print(currentFileName)

    // Save Images
    let fileMgr = FileManager.default
    let dirPath = fileMgr.urls(for: .documentDirectory, in: .userDomainMask)[0]
    let imageFileUrl = dirPath.appendingPathComponent(currentFileName)



        do {

            try UIImagePNGRepresentation(returnedImages)!.write(to: imageFileUrl)

            print("Image Added Successfully")

    } catch {

        print(error)

        }
Run Code Online (Sandbox Code Playgroud)

下面是我用来检索图像的代码,但是我正在获取URL而不是图像文件来填充tableview。任何帮助,将不胜感激

   let fileManager = FileManager.default
   let imageUrl = fileManager.urls(for: .documentDirectory, in: .userDomainMask) [0].appendingPathComponent("img")

   print("Your Images:\(imageUrl)")
Run Code Online (Sandbox Code Playgroud)

nsdocumentdirectory swift swift3 xcode8

0
推荐指数
1
解决办法
3289
查看次数

@available api检查在Xcode 8中不起作用

我正在编写Xcode 8.0中的objective-c代码,用于我正在使用的API可用性

 if (@available(iOS 11, *)) {
        // iOS 11 (or newer) ObjC code
 } else {
        // iOS 10 or older code
 }
Run Code Online (Sandbox Code Playgroud)

不幸的是编译器触发:

无法识别的平台名称iOS

为什么?

xcode objective-c xcode8

0
推荐指数
1
解决办法
2608
查看次数