Ios 包含数据的两个表视图,并希望从一个特定的表视图中删除索引。我是否也必须删除另一个数组?

Ios 包含数据的两个表视图,并希望从一个特定的表视图中删除索引。我是否也必须删除另一个数组?,ios,swift,xcode,uitableview,memory,Ios,Swift,Xcode,Uitableview,Memory,好的,我从中得到了内存错误,这很烦人,因为它不像一个简单的语法错误。我正在做的事情是为了理解如何操作数据 我试图做的是允许它从另一个视图中删除,但它仍然崩溃。我将分享我正在进行的两个表格视图 这是有问题的一个,因为它位于第二个视图控制器中 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return FeedCommands.commentSection.co

好的,我从中得到了内存错误,这很烦人,因为它不像一个简单的语法错误。我正在做的事情是为了理解如何操作数据

我试图做的是允许它从另一个视图中删除,但它仍然崩溃。我将分享我正在进行的两个表格视图

这是有问题的一个,因为它位于第二个视图控制器中

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return FeedCommands.commentSection.count
}

//allows us to delete the code
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
     if editingStyle == .delete {
        // this is called from a static variable class function
        FeedCommands.RemoveComment(atIndex: indexPath.row)
        CommentFeed.deleteRows(at: [indexPath], with: .fade)
     }
}
这是一个非常好用的

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return FeedCommands.feedArray.count
}

func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
    if editingStyle == .delete {
       FeedCommands.feedArray.remove(at: indexPath.row)
       TabView.deleteRows(at: [indexPath], with: .fade)
    }
}
如果我运行的问题之一,它存在一个内存错误,我认为它可能必须处理数组,可能是实际原因。我搜索了一下,在执行多个TableView时,似乎并没有任何内容涵盖这个案例

这是我调用数组的类

static var commentSection: Array<String> = []
class func AddToComment(newElement: String){
   FeedCommands.commentSection.append(newElement)
}
class func RemoveComment (atIndex: Int){
    FeedCommands.commentSection.remove(at: atIndex)
}

static var QuestionToComment: Array<String> = []
class func AddQuestionToComment(newElement: String){
    FeedCommands.QuestionToComment.append(newElement)
}
class func RemoveQuestionToComment (atIndex: Int){
    FeedCommands.QuestionToComment.remove(at: atIndex)
}

static var feedArray: Array<String> = []

class func AddToFeed (newElement: String){
    FeedCommands.feedArray.append(newElement)
}
class func Remove (atIndex: Int){
    FeedCommands.feedArray.remove(at: atIndex)
}

在将新元素追加到表视图之前重新加载表视图数据,而不是在追加回复之后重新加载。这就是为什么你需要按两次按钮才能让它出现。要修复submit-reply操作,您应该在每次按下SubmitReply按钮时在表视图的最后一个索引(count-1)处插入新行:

@IBAction func SubmitReply(_ sender: UIButton) {
    if !ReplyTextField.text!.isEmpty{
        FeedCommands.AddToComment(newElement: ReplyTextField.text!)
        ReplyTextField.text = ""
        CommentFeed.insertRows(at: [IndexPath(row: FeedCommands.commentSection.count-1, section: 0)], with: .automatic)
    }
}

在将新元素追加到表视图之前重新加载表视图数据,而不是在追加回复之后重新加载。这就是为什么你需要按两次按钮才能让它出现。要修复submit-reply操作,您应该在每次按下SubmitReply按钮时在表视图的最后一个索引(count-1)处插入新行:

@IBAction func SubmitReply(_ sender: UIButton) {
    if !ReplyTextField.text!.isEmpty{
        FeedCommands.AddToComment(newElement: ReplyTextField.text!)
        ReplyTextField.text = ""
        CommentFeed.insertRows(at: [IndexPath(row: FeedCommands.commentSection.count-1, section: 0)], with: .automatic)
    }
}

什么是“内存错误”?它在哪里坠毁?它崩溃的特定行上的具体错误是什么?好的,内存错误是中止的东西,直接带我到应用程序委托部分。“线程1:信号SIGABRT”。当我执行我所说的第一个代码时,它崩溃了,正如我在promptAlso中所说的那样,我检查了我所有的主情节提要,它们没有任何警告。视图控制器也很好,因为它工作得很好,但我首先提到的是有问题的那个。我贴了一个能给你更多线索的,因为这些是我能提供的最好的,除非你想要整个源代码,这相当于一本小说。它崩溃在哪一行?这个正在工作什么是“内存错误”?它在哪里坠毁?它崩溃的特定行上的具体错误是什么?好的,内存错误是中止的东西,直接带我到应用程序委托部分。“线程1:信号SIGABRT”。当我执行我所说的第一个代码时,它崩溃了,正如我在promptAlso中所说的那样,我检查了我所有的主情节提要,它们没有任何警告。视图控制器也很好,因为它工作得很好,但我首先提到的是有问题的那个。我贴了一个能给你更多线索的,因为这些是我能提供的最好的,除非你想要整个源代码,这相当于一本小说。它崩溃在哪一行?你让我高兴得流下了眼泪。非常感谢你,你让我喜出望外。多谢各位