self.tableView reloadData]; // 屏幕上的所有可视的cell都会刷新一遍 局部刷新方法 添加数据 NSArray *indexPaths = @[ [NSIndexPath indexPathForRow:0 inSection:0], [NSIndexPath indexPathForRow:1 inSection:0] withRowAnimation:UITableViewRowAnimationRight]; 删除数据 NSArray *indexPaths = @[ [NSIndexPath indexPathForRow:0 inSection:0], [NSIndexPath indexPathForRow:1 inSection:0] indexPathForRow:0 inSection:0], [NSIndexPath indexPathForRow:1 inSection:0]
Paste_Image.png 1)确定 cell 是否处于编辑状态 -(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath 添加) -(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath -(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath { return YES; } 2.移动 -(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath
*)indexPath; 设置某行是否可以被移动 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath; 三、UITableViewDelegate(tableView代理 *)indexPath; - (void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *) willSelectRowAtIndexPath:(NSIndexPath *)indexPath; - (NSIndexPath *)tableView:(UITableView *)tableView :(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath; 疏漏之处
作用 allowsSelection BOOL 允许选中 allowsMultipleSelection BOOL 允许多选 indexPathsForSelectedRows NSArray < NSIndexPath *> 获取当前选中cell的indexPaths indexPathsForVisibleRows NSArray < NSIndexPath *> 当前可见行数 allowsSelection: 2.1 最最常用的方法:选中指定的cell //选中cell -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { ``` //修改删除按钮文字 (NSString *) tableView:( UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
可见的cell数组 NSArray * array = [_rightTableView visibleCells]; //返回cell的IndexPath NSIndexPath ]; NSLog(@"滑到了第 %ld 组 %ld个",indexPath.section, indexPath.row); _currentIndexPath = [NSIndexPath indexPath.section]; [_leftTableView reloadData]; [_leftTableView scrollToRowAtIndexPath:[NSIndexPath ]; NSLog(@"滑到了第 %ld 组 %ld个",indexPath.section, indexPath.row); _currentIndexPath = [NSIndexPath indexPath.section]; [_leftTableView reloadData]; [_leftTableView scrollToRowAtIndexPath:[NSIndexPath
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath :(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath 是否可以被移动,返回NO则不能移动 - (BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(NSIndexPath ); 移动item的时候,会调用这个方法 - (void)collectionView:(UICollectionView *)collectionView moveItemAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath*)destinationIndexPath; 三、UICollectionViewDelegate协议
通常在代理 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 返回不同的cell,甚至需要在在 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath group.rowNumber; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath pragma mark - UITableViewDelegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath identifier:KHomeCellStyleOneIdentifier]; cellOne.configCellComplete = ^(UITableViewCell *cell, NSIndexPath
UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath //实现此方法,就可以移动单元格, 方法里面是让数据和样式移动保持一致 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{ // NSLog(@"移动了”"); TanPerson
UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath HJDownloadManager 移除任务示例 - (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath rowActionWithStyle:UITableViewRowActionStyleDefault title:@"删除" handler:^(UITableViewRowAction *action, NSIndexPath UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath
*)indexPath; 获取某个点在tableView中的位置信息 - (NSIndexPath *)indexPathForRowAtPoint:(CGPoint)point; 获取某个cell 在tableView中的位置信息 - (NSIndexPath *)indexPathForCell:(UITableViewCell *)cell; 根据一个矩形范围返回一个信息数组,数组中是每一行 *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation; 移动某行 - (void)moveRowAtIndexPath:(NSIndexPath 代码示例如下: [tab beginUpdates]; [tab deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:1 inSection 获取多选cell的位置信息 - (NSArray *)indexPathsForSelectedRows; 代码手动选中与取消选中某行 - (void)selectRowAtIndexPath:(NSIndexPath
*)indexPath; //非选中 - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath 之后,通过屏幕点击选中其它cell的时候,可以执行- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath 比较 比如,下面两种方案 NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; UICollectionViewCell [self.collectionView selectItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0] animated:YES 如果你真的想在改变选中状态的时候执行didSelect代理,那么可以手动执行: NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection
self.sumCount =[UIScreen mainScreen].bounds.size.height/40; } - (void)selectRowAtIndexPath:(nullable NSIndexPath YES]; } //设置每行的单元格的内容 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath )tableView { return 1; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath self.shouDatas.count==self.count) { self.count=0; [self.showTableView selectRowAtIndexPath:[NSIndexPath UITableViewScrollPositionBottom]; } else { [self.showTableView selectRowAtIndexPath:[NSIndexPath
得到当前正在显示的cell的indexPath,(只有一个) NSIndexPath *currentIndexPath = [[self.collectionView indexPathsForVisibleItems 得到YYMaxSections/2对应的section的indexPath,显示此indexPath对应的cell NSIndexPath *currentIndexPathReset = [NSIndexPath 位移显示效果 NSIndexPath *nextIndexPath = [NSIndexPath indexPathForItem:nextItem inSection:nextSection]
*indexPath = [NSIndexPath indexPathForRow:arc4random() % 10 inSection:0]; [insertBodys addObject *)userIndexPathByFeeds:(NSIndexPath *)feedsIndexPath { if (! *> *array = self.sectionMap[@(section)]; NSInteger cutCount = 0; for (NSIndexPath *obj in array *)userIndexPathByFeeds:(NSIndexPath *)feedsIndexPath { if (! *> *array = self.sectionMap[@(section)]; NSInteger cutCount = 0; for (NSIndexPath *obj in array
*)collectionView: (UICollectionView *)collectionView 5 cellForItemAtIndexPath: (NSIndexPath viewForSupplementaryElementOfKind: (NSString *)kind 6 atIndexPath: (NSIndexPath / 6 - (BOOL)collectionView: (UICollectionView *)collectionView 7 shouldHighlightItemAtIndexPath: (NSIndexPath 1 /** 2 * 根据高亮状态修改背景图片 3 */ 4 - (void) changeHighlightCellWithIndexPaht: (NSIndexPath *) indexPath */ 4 - (void)collectionView: (UICollectionView *)collectionView 5 didHighlightItemAtIndexPath: (NSIndexPath
*)indexPath; //获取某一点所在的indexpath位置 - (nullable NSIndexPath *)indexPathForItemAtPoint:(CGPoint)point ; //获取某个cell所在的indexPath - (nullable NSIndexPath *)indexPathForCell:(UICollectionViewCell *)cell; / /根据indexPath获取cell - (nullable UICollectionViewCell *)cellForItemAtIndexPath:(NSIndexPath *)indexPath :(NSArray<NSIndexPath *> *)indexPaths; - (void)moveItemAtIndexPath:(NSIndexPath *)indexPath toIndexPath :(NSIndexPath *)newIndexPath; 专注技术,热爱生活,交流技术,也做朋友。
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath - (NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath - (void)tableView :(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath 当有点击事件发生时,运行顺序为。 -(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath <cellCount { let indexPath = NSIndexPath(forItem:i, inSection:0) let attributes } // 这个方法返回每个单元格的位置和大小 override func layoutAttributesForItemAtIndexPath(indexPath: NSIndexPath } func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath
预加载数据 - (void)collectionView:(UICollectionView *)collectionView prefetchItemsAtIndexPaths:(NSArray<NSIndexPath void)collectionView:(UICollectionView *)collectionView cancelPrefetchingForItemsAtIndexPaths:(NSArray<NSIndexPath - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *> *)indexPaths { for (NSIndexPath * indexPath in indexPaths) { NSURL *currentURL *> *)indexPaths { for (NSIndexPath * indexPath in indexPaths){ NSURL *currentURL
返回indexPath位置cell对应的布局属性*/ -(UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryViewOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath item等宽不等高 */ -(CGFloat)waterFlowLayout:(WSLWaterFlowLayout *)waterFlowLayout heightForItemAtIndexPath:(NSIndexPath item等高不等宽 */ -(CGFloat)waterFlowLayout:(WSLWaterFlowLayout *)waterFlowLayout widthForItemAtIndexPath:(NSIndexPath 列数、行数无用 */ - (CGSize)waterFlowLayout:(WSLWaterFlowLayout *)waterFlowLayout sizeForItemAtIndexPath:(NSIndexPath