Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios &引用;尝试从第1节中删除行,但更新前只有1节;_Ios_Swift_Uitableview - Fatal编程技术网

Ios &引用;尝试从第1节中删除行,但更新前只有1节;

Ios &引用;尝试从第1节中删除行,但更新前只有1节;,ios,swift,uitableview,Ios,Swift,Uitableview,我试图删除不符合for循环条件的行。但是,我得到了一个错误,上面写着:“尝试从第1节中删除第0行,但在更新之前只有1节。”我以前从未看到过这一点,也不知道为什么会得到它 我的代码: func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = theTableView.dequeueReusableCellW

我试图删除不符合for循环条件的行。但是,我得到了一个错误,上面写着:“尝试从第1节中删除第0行,但在更新之前只有1节。”我以前从未看到过这一点,也不知道为什么会得到它

我的代码:

 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell = theTableView.dequeueReusableCellWithIdentifier("MyCell") as! TableViewCell
    cell.titleLabel.text = titles[indexPath.row]
    cell.priceLabel.text = prices[indexPath.row]
    cell.descLabel.text = descs[indexPath.row]
    cell.itemImage.image = itemImages[indexPath.row]
    cell.userNumber = phoneNumbers[indexPath.row] as! String
    cell.timeLabel.text = datesHours[indexPath.row]! + "hr"
    cell.distanceLabel.text = String(locations[indexPath.row]!) + "mi"
    cell.viewController = self




    self.theTableView.beginUpdates()

    for (index, number) in self.locations {
        if number <= 5 {
            let indexPath = NSIndexPath(forRow: number, inSection: 1)
            self.theTableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)

        }
    }
    self.theTableView.endUpdates()
func tableView(tableView:UITableView,cellForRowAtIndexPath:nsindepath)->UITableView单元格{
让cell=TableView.dequeueReusableCellWithIdentifier(“MyCell”)作为!TableViewCell
cell.titleLabel.text=标题[indexPath.row]
cell.pricellabel.text=价格[indexPath.row]
cell.descLabel.text=descs[indexPath.row]
cell.itemImage.image=itemImages[indexPath.row]
cell.userNumber=phoneNumbers[indexPath.row]作为!字符串
cell.timeLabel.text=datesHours[indexPath.row]!+“hr”
cell.distanceLabel.text=字符串(位置[indexPath.row]!)+“mi”
cell.viewController=self
self.theTableView.beginUpdate()
在self.location中的(索引、编号){

如果number似乎是在告诉表将有比实际要显示的行更多的行,然后在事实发生后删除它们

相反,您应该检查数组中的元素是否满足中(或之前)的条件
numberOfRowsInSection
并将它们放入实际显示的不同数组中,以便表格知道实际显示的行数。然后在
cellForRowAtIndexPath
中,只需使用新创建的数组,该数组包含实际显示的数据

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // Return the number of rows in the section.

        self.displayArray = []
        for (index, number) in self.locations {
            if number <= 5 {
               self.displayArray.Add(self.locations[index])
            }
        }
        return self.displayArray.Count
    }
override func tableView(tableView:UITableView,numberofrowsinssection:Int)->Int{
//返回节中的行数。
self.displayArray=[]
在self.location中的(索引、编号){

如果在
单元格内调用
reloadrowsatindexpath
的原因是什么?这不是一个好主意,您建议我怎么做?如果我用另一种方法调用redoadrowsatindexpath,我无法访问我的arrays@theActuary那没有意义什么阵列?你还没弄清楚生命周期beca使用您可能还没有想清楚。是什么事件导致行被删除?无论是什么事件,您都会将
for
循环放入它的处理程序中。CellForRowatinedExath的唯一任务是计算一个已知在表中的单元格。其他什么都没有。