UITableView UITableViewCell NSIndexPath
来源:互联网 发布:mac怎么显示图片尺寸 编辑:程序博客网 时间:2024/06/05 20:02
--------------------------------------------------------------------------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];注:@selector 可以获取 UIEvent 对象
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下载地址:
https://github.com/alekseyn/EasyTableView
2:经过我添砖加瓦的版本:
http://download.csdn.net/detail/ysy441088327/4675946
从iOS6以上开始 有了UITableView的亲兄弟 UICollectionView. 它带来更加强大的布局功能.
7:提前获取UITableView 的ContentSize
[flowCalendarTableView.tableView layoutIfNeeded];NSLog(@"%@",NSStringFromCGSize(flowCalendarTableView.tableView.contentSize));8: 去掉UITabelView 默认的 Cell间隔线条
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;9: 下拉刷新实现原理
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; }];}注:删除按钮出来时肯定有动画,但是消失时不一定有动画,原因是看你有没有实现 这个委托 accessoryTypeForRowWithIndexPath(搜索一下)
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---------------------------------------------------------------------------------------
- UITableView UITableViewCell NSIndexPath
- UITableView UITableViewCell NSIndexPath
- UITableView 中NSIndexPath
- UITableView NSIndexPath属性讲解
- UITableViewCell 和NSIndexPath互取
- IOS UITableView NSIndexPath属性讲解
- IOS UITableView NSIndexPath属性讲解
- iOS UITableView NSIndexPath属性讲解
- IOS UITableView NSIndexPath属性讲解***
- UITableView&UITableViewCell
- NSIndexPath UITableView移动到下一个行
- 黑马程序员-IOS UITableView NSIndexPath属性讲解
- NSIndexPath
- NSIndexPath
- UITableView,UITableViewCell,UIPickerView,UISearchBar
- UITableView与UITableViewCell
- UITableView与UITableViewCell
- UITableView,UITableViewCell,UIPickerView,UISearchBar
- 通过写framebuffer显示BMP图片
- C语言高效编程的的四大绝招
- 57 有舍才有得
- Ruby连Mysql数据库
- debug with dump at Visual Studio 2005
- UITableView UITableViewCell NSIndexPath
- 缓存几种形式
- Oracle DBlink
- 20110418_批处理sql 语句的写法_oracle !!的使用
- 规格模式 hql仿设计
- 黑马程序——关于函数(黑马我来了之三)
- List of Features with GUIDs
- android 镜像文件ramdisk system userdata
- 提高网站的访问速度、安全、扩展性方面问题