行选择重新创建UiTableViewCell

时间:2015-01-01 17:51:49

标签: ios uitableview swift

我正在创建一个带有2个不同单元格笔尖的UiTableView。它完全正常,期待一个特定的场景。

ISSUE: 在单元格选择上,我在didSelectRowAtIndexPath中执行一些操作。执行didSelectRowAtIndexPath后,iOS会调用cellForRowAtIndexPath方法并重新创建该单击的单元格。

娱乐的影响是什么: 我的细胞高度是动态的。当UiTableView从中间重新创建任何单元格时,它会导致向后/向上滚动时出现不自然的抖动。

以下是我的方法的代码段。任何帮助都会受到关注:)

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


        var post = self.posts[indexPath.row]

        if(post.valueForKey(MEDIA) != nil) {
            var cell:PostImageTableViewCell = self.tableView.dequeueReusableCellWithIdentifier("PicCell") as PostImageTableViewCell
            cell.loadPostData(post)
            return cell
        } else {
            var cell:PostTableViewCell = self.tableView.dequeueReusableCellWithIdentifier("Cell") as PostTableViewCell
            cell.loadPostData(post)
            return cell
        }
    }

选择方法:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

        self.selectedRow = indexPath.row
        self.performSegueWithIdentifier("detailSegue", sender: nil);
        self.tableView.deselectRowAtIndexPath(indexPath, animated: true)
    }

致电堆栈:

enter image description here

0 个答案:

没有答案