简体   繁体   中英

Will UICollectionView change the cell's selected property to true before sending didSelectItemAtIndexPath delegate method?

The question is described above. Do I have to call UICollectionView's selectItemAtIndexPath method in the delegate method didSelectItemAtIndexPath, or does UICollectionView already did that for me?

Yes. By the time didSelectItemAtIndexPath is called, the selected property has already been set to TRUE .

To verify simply add:

NSLog(@"selected: %i", [collectionView cellForItemAtIndexPath:indexPath].selected);

to your didSelectItemAtIndexPath method and you will see it will come back true (1)

There is a willSelectRowAtIndexPath method and a didSelect... method. The selection won't be changed when the willSelect... method is called, and WILL be changed on the did-select. (The willSelectRowAtIndexPath gives you a chance to change/cancel the selection before it occurs if you want to.)

This is a strong naming convention in the iOS frameworks. The tense of the verb in the method name tells you whether the event has occurred yet when the method is called (eg viewWillAppear and viewDidAppear . The viewWillAppear method is called before a view is shown, and viewDidAppear is called AFTER the view is shown.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM