小编inf*_*ouk的帖子

从Swift 3中的UITableView删除一行?

我是编程和学习swift的新手,我正在学习swift 2的教程并使用swift 3,因此我跟随时会遇到一些问题,这是一个我已经适当坚持的问题.

我有一个名称表,我正在为它们制作一个滑动和删除功能,它将它们从名称变量中删除,这是一个数组.我在xcode中选择了与教程最相似的函数并将它们填满,但是当我单击删除按钮时,我的应用程序随机崩溃.这是删除按钮的代码...

    func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {

    let deleteAction = UITableViewRowAction(style: .destructive, title: "Delete") { (rowAction: UITableViewRowAction, indexPath: IndexPath) -> Void in

        print("Deleted")

        self.catNames.remove(at: indexPath.row)
        self.tableView.deleteRows(at: [indexPath], with: UITableViewRowAnimation.automatic)
        self.tableView.reloadData()
    }
Run Code Online (Sandbox Code Playgroud)

row uitableview swift

38
推荐指数
3
解决办法
6万
查看次数

'为CoreData实体创建NSManagedObject子类后的错误

我创建了2个核心数据实体,然后从编辑器菜单为它们创建了NSManagedObject子类.

但是,当我运行我的应用程序时,由于某种原因,我在所有文件的每一行都会出错.

这是一个例子,这两个实体创建的文件的错误是相同的.

在此输入图像描述

文件代码是自动生成的,所以我可以在这里使用它,但不确定它的用途

    import Foundation
import CoreData


extension UserExercise {

    @nonobjc public class func fetchRequest() -> NSFetchRequest<UserExercise> {
        return NSFetchRequest<UserExercise>(entityName: "UserExercise");
    }

    @NSManaged public var id: Int16
    @NSManaged public var name: String?
    @NSManaged public var reps: Int16
    @NSManaged public var sets: Int16
    @NSManaged public var weight: Int16
    @NSManaged public var relationship: NSSet?

}

// MARK: Generated accessors for relationship
extension UserExercise {

    @objc(addRelationshipObject:)
    @NSManaged public func addToRelationship(_ value: UserRoutine)

    @objc(removeRelationshipObject:)
    @NSManaged public func removeFromRelationship(_ value: UserRoutine)

    @objc(addRelationship:)
    @NSManaged public …
Run Code Online (Sandbox Code Playgroud)

core-data swift

19
推荐指数
3
解决办法
5563
查看次数

在扩展文件中使用未解析的标识符错误?

我正在进行扩展,将html转换为属性字符串,代码为

extension String {
var htmlToAttributedString: NSAttributedString? {
    guard let data = data(using: .utf8) else { return nil }
    do {
        return try NSAttributedString(data: data, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: String.Encoding.utf8.rawValue], documentAttributes: nil)
    } catch let error as NSError {
        print(error.localizedDescription)
        return  nil
    }
}
var html2String: String {
    return htmlToAttributedString?.string ?? ""
}
Run Code Online (Sandbox Code Playgroud)

我收到以下3个相同的错误

使用未解析的标识符'NSDocumentTypeDocumentAttribute'

使用未解析的标识符'NSHTMLTextDocumentType'

使用未解析的标识符'NSCharacterEncodingDocumentAttribute'

我假设我犯了一个错误的语法导致3相同的错误但我无法看到扩展需要什么?

谢谢

nsattributedstring swift swift3

7
推荐指数
1
解决办法
4431
查看次数

将Int保存到核心数据中的正确方法?

我有一个具有Int16属性的实体。

在此处输入图片说明

我想保存var userRepsCount = Int()以下步进方法设置的内容:

@IBAction func userRepsStepper(_ sender: UIStepper) {
    userExerciseRepsCounter.text = Int(sender.value).description
    self.userRepsCount = Int(sender.value)
}
Run Code Online (Sandbox Code Playgroud)

我想将此添加到属性并正在使用userExercise.reps = userRepsCount,但是出现错误

无法将类型“ Int”的值分配给类型“ Int16”

我的印象是Int16可以毫无问题地存储int这样的int?我在这里想念什么?

core-data swift

5
推荐指数
1
解决办法
6454
查看次数

过滤数组并在表格视图中显示?

我想搜索名称键的练习字典,然后在表格视图中显示过滤结果.我正在使用这个功能

func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
    let filtered = exercises.filter { $0["name"] == searchText }
    print(filtered)

    if(filtered.count == 0){
        searchActive = false;
    } else {
        searchActive = true;
    }
    self.exercisesTableView.reloadData()
}
Run Code Online (Sandbox Code Playgroud)

变量:

var exercises = [Exercise]()
var filtered: [NSMutableArray] = []
var searchActive: Bool = false
Run Code Online (Sandbox Code Playgroud)

在搜索功能中,我收到错误

Type'Exercise'没有下标成员

然后我有一个问题,结果是一个NSMutableArray,所以我不能将结果名称设置为单元格文本来显示

无法将'NSMutableArray'类型的值转换为强制类型'String'

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
    if (searchActive){
        cell.textLabel?.text = filtered[indexPath.row] as String
    } else { …
Run Code Online (Sandbox Code Playgroud)

uitableview uisearchbar swift

3
推荐指数
2
解决办法
7640
查看次数

将分隔符添加到UINavigationBar - iOS

我注意到苹果时钟应用程序的标题上有一个细条,可以很好地将其与内容分开,并使界面看起来略微3D.我想在我自己的导航栏上复制这个但是看不到这样做的方法?我怎么做到这一点

计时器

我的应用

iphone uinavigationbar ios swift

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