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]
*)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 {
- (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
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
可见的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
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; //非选中 - (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
*)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 = [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 layout:(UICollectionViewLayout *)**collectionViewLayout sizeForItemAtIndexPath**:(NSIndexPath :(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath 瀑布流.png 核心实现是在方法: - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath 动态布局.gif 主要实现的过程用到了 一些新的collection view方法: beginInteractiveMovementForItemAtIndexPath(indexPath: NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath*)destinationIndexPath{ id obj = [_data objectAtIndex
[array count]; } } - (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath } return cell; } -(void)tableView:(UITableView *)tv didSelectRowAtIndexPath:(NSIndexPath tableView:(UITableView *)tv commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath } -(UITableViewCellEditingStyle )tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath indexPathForRow:i inSection:0]]; } NSArray *lastIndex=[NSArray arrayWithObject:[NSIndexPath
这几天被这个基础控件搞的头疼 第一种方法: 纯手码(最土的方法) - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath Paste_Image.png - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath Paste_Image.png - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath indexPath]; } } - (UITableViewCell *)cell1:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath ID]; return cell; } - (UITableViewCell *)cell2:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
有以下几个注意点: - 首先在```- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *) 首先我们先声明一个变量,用来存储被选择的行数的标志 @property (nonatomic, strong) NSIndexPath *selectPath; //存放被点击的哪一行的标志 之后我们实现 ```- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath```这个代理方法 (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ int newRow YES]; } 最后看一下怎么在```- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
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]
预加载数据 - (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
-(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