--------------------------------------------------------------------------NSIndexPath-------------------------------------------------------------------------
1:初始化NSIndexPath (来自: Kid)
inSection 表示TableView 的分组的 第一组数据.
- NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
2:IndexPath 对比是否相同
- [easyTableView.selectedIndexPath isEqual:indexPath]
3:通过UITableViewCell 里面的按钮事件 来获取 该按钮所在的IndexPath
1:注册事件:
- [selectButton addTarget:self action:@selector(FE_selectAnnotation:withEvent:) forControlEvents:UIControlEventTouchUpInside];
- NSIndexPath *indexPath = [tableView indexPathForRowAtPoint: [[[event touchesForView: btn] anyObject] locationInView:tableView]];
- NSLog(@"%d",indexPath.row);
--------------------------------------------------------------------------NSIndexPath--------------------------------------------------------------------------
------------------------------------------------------------------------------------UITableView------------------------------------------------------------------------------------------
1:UITableView reLoadData 重载动态数据时的注意.
因为UITableView的Cell 是以重用的方式去显示数据,所以对Cell中动态数据 都需要设置. 否则可能会乱掉
2:去除选中某行Cell的状态
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
3:使用静态UITableView时此委托不要实现,否则在运行时将出现警告
- -(UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath
- {
- if ([indexPath row] == 0) {
- return UITableViewCellAccessoryDisclosureIndicator;
- }else {
- return UITableViewCellAccessoryNone;
- }
- }
4:滑动删除按钮必须同时实现以下两个委托,才能生效
- -(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return YES;
- }
- -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
- NSLog(@"%d",indexPath.row);
- }
5:在使用UITableView 的
tableHeaderView 时 丢进去的View需要先行设置好 Frame 不然会与后面生成Cell产生重叠的问题
6:UITableView 默认 只支持垂直 可以通过transForm 旋转达到支持水平形式的UITableView
1:网上开源Demo下载地址:
2:经过我添砖加瓦的版本:
从iOS6以上开始 有了UITableView的亲兄弟 UICollectionView. 它带来更加强大的布局功能.
7:提前获取UITableView 的ContentSize
- [flowCalendarTableView.tableView layoutIfNeeded];
- NSLog(@"%@",NSStringFromCGSize(flowCalendarTableView.tableView.contentSize));
- tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- CGFloat offset = MAX(scrollView.contentOffset.y * -1, 0);
- offset = MIN(offset, 60);
- scrollView.contentInset = UIEdgeInsetsMake(offset, 0.0f, 0.0f, 0.0f);
10:开启排序拖动编辑功能
- //开启排序拖动编辑功能
- - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
- {
- NSLog(@"1");
- }
11:滑动显示删除按钮时和结束按钮操作时所触发的委托,可以在这两个委托里面控制 Cell内部Frame
- - (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
- {
- [UIView animateWithDuration:0.25 animations:^{
- FEUIFriendGroupCell *cell = (FEUIFriendGroupCell *)[tableView cellForRowAtIndexPath:indexPath];
- cell.friendGroupTitleTextField.Help_width -=60;
- }];
- }
- - (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath
- {
- [UIView animateWithDuration:0.25 animations:^{
- FEUIFriendGroupCell *cell = (FEUIFriendGroupCell *)[tableView cellForRowAtIndexPath:indexPath];
- cell.friendGroupTitleTextField.Help_width +=60;
- }];
- }
12:让UIPanGestureRecognizer 与 UItableView 的滑动显示 删除按钮 共存
- [[tableView gestureRecognizers] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
- if ([NSStringFromClass([obj class]) isEqualToString:@"UISwipeGestureRecognizer"]) {
- [self.bookContentContainerView.touchPanGesture requireGestureRecognizerToFail:obj];
- }
- }];
13:开启UITableView多选编辑功能(iOS 5 or later):
- [multiFTPServerListTableView setAllowsMultipleSelectionDuringEditing:YES];
- [multiFTPServerListTableView setEditing:YES];
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- NSLog(@"%@",[tableView indexPathsForSelectedRows]);
- NSArray *indexPathArray = [tableView indexPathsForSelectedRows];
- [indexPathArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
- if ([indexPath isEqual:obj] == NO) {
- [tableView deselectRowAtIndexPath:obj animated:NO];
- }
- }];
- }
14:让已经选择了多个Cell以后立刻去除所有已选中的效果:
- _documentCollectionView.allowsMultipleSelection = NO;
- _documentCollectionView.allowsSelection = NO;
- _documentCollectionView.allowsSelection = YES;
------------------------------------------------------------------------------------UITableView------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------UITableViewCell---------------------------------------------------------------------------------------
1:设置TableViewCell 的背景颜色
- UIView *backgrdView =[[UIView alloc] initWithFrame:self.frame];
- backgrdView.backgroundColor=[UIColor colorWithRed:242.0/255 green:242.0/255 blue:242.0/255 alpha:1];
- self.backgroundView= backgrdView;
- [backgrdView release];
例如:Cell 高度 有100 但其实只有显示 50.
第一步是设置好UITableView 没列的高度,通过以下委托
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return 50;
- }
第二步 将UITableViewCell 自身设置为 自动遮罩不可见区域
- [self.layer setMasksToBounds:YES];
3:为自定义UITableViewCell 设置 reuseIdentifier
在Cell.h 头文件添加
静态取值方法:
- + (NSString *)reuseIdentifier;
在Cell.m体文件添加
- //因为是继承关系 所以重写Cell 的 reuseIdentifier 以确定 其值.
- -(NSString *)reuseIdentifier
- {
- return @"FEUIAddressBookCell";
- }
- //定义一个静态方法来取其值.
- +(NSString *)reuseIdentifier
- {
- return @"FEUIAddressBookCell";
- }
UITableView 调用时如下:
- NSString *SectionsTableIdentifier = [FEUIAddressBookCell reuseIdentifier];
- FEUIAddressBookCell *addressBookCell = (FEUIAddressBookCell *)[tableView dequeueReusableCellWithIdentifier:SectionsTableIdentifier];
- if(addressBookCell == nil)
- {
- NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"FEUIAddressBookCell" owner:self options:nil];
- addressBookCell = (FEUIAddressBookCell *)[nib objectAtIndex:0];
- }
通过如上,性能问题已经解决.继续施展拳脚吧!!!
4:UITableView 在Grouped 模式下. 修改Cell 背景颜色的方式
- cell.backgroundColor = [UIColor whiteColor];
5:不要在Cell内部的任何控件 使用 setMasksToBounds , 否则拖动动画不流畅
6:设置Cell系统高亮选择样式风格
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
注:上面表示取消了.系统默认的高亮选择效果.
---------------------------------------------------------------------------------UITableViewCell---------------------------------------------------------------------------------------