我是Obj-C的新手。当我选择一个有selectItemAtIndexPath:animated:scrollPosition:
的单元格时,它不会被调用。我称它们为didSelectItemAtIndexPath:
,最终效果是一样的。
它们之间有什么区别?
您提到的第一个方法(selectItemAtIndexPath:animated:scrollPosition:
)实际上选择了所提供的indexPath中的项。可选的,它也可以滚动到它。
您提到的第二个方法(scrollToItemAtIndexPath:atScrollPosition:animated:
)只滚动集合视图,直到指定的项可见为止。它不会选择它
在你的例子中,如果我理解正确的话,你是在描述一个项目已经被选中的场景(didSelectItemAtIndexPath:
),所以你只需要调用第二个方法,如果你想确保项目是可见的(它不需要再次被选中)。或者,您可以将原始方法(selectItemAtIndexPath:animated:scrollPosition:
)替换为selectItemAtIndexPath:animated:scrollPosition:
以选择单元格(但是,请注意,根据规范,正如您原始问题的评论中提到的那样,"此方法不会导致调用任何与选择相关的委托方法",因此您将不会收到didSelectItemAtIndexPath:
调用。