UITableView学习笔记
2014-04-17 21:16
369 查看
1、UITableView中Cell的操作
链接地址:/article/3457434.html2、UITableView索引搜索之UILocalizedIndexedCollation
/article/1348971.html/article/10157043.html
5、单元格附属视图和缩进
/article/1348999.htmlUIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];//初始化按钮 button.frame = CGRectMake(0.0f,0.0f,150.0f,25.0f);//设置大小 [button setTitle:[NSString stringWithFormat:@"Expand %ld",(long)indexPath.row] forState:UIControlStateNormal];//设置按钮标题和常态样式 [button addTarget:self action:@selector(performExpand:) forControlEvents:UIControlEventTouchUpInside];//添加点击事件 cell.accessoryView = button; cell.indentationLevel = indexPath.row;//缩进等级 cell.indentationWidth = 10.0f;//缩进宽度
6、显示长按快捷菜单
/article/1348996.html//允许长按菜单 -(BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath{ return YES; } //允许每一个Action -(BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender{ NSLog(@"%@",NSStringFromSelector(action)); return YES; } //对一个给定的行告诉代表执行复制或粘贴操作内容, -(BOOL)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender{ if (action==@selector(copy:)) {//如果操作为复制 UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];//黏贴板 [pasteBoard setString:cell.textLabel.text]; NSLog(@"%@",pasteBoard.string);//获得剪贴板的内容 return YES; } return NO; }
11、设置Cell选中状态的背景色:
UIView *bgView = [[UIView alloc] init]; bgView.backgroundColor = [UIColor orangeColor]; self.selectedBackgroundView = bgView;该方法设置的是纯色, 也可以使用任何图片,把selectedBackgroundView设成UIImageView。
除了上面的方法,还有一种方法:重写UITableViewCell 的 setSelected:animated:
- (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; if (selected) { self.backgroundColor = RGB(224, 152, 40); } else { self.backgroundColor = [UIColor clearColor]; } }
12、取table中控件的位置
如果Table中有控件,这里以switch为例(适合其它可修改值的各种控件),要在switch的UIControlEventValueChanged事件的处理方法里把变化记录下来。以下方法是不可取的:在执行的最后把所有cell遍历一遍,处理各控件的值。因为没显示出来的cell,是取不到的,当然也就取不到该cell里的控件。所以正确的做法是,在控件可见时,如果值变了,立即处理。当然,如果你的Cell少,不会出现隐藏的情况就随便了13、闪一下滚动条:flashScrollIndicators
闪一下滚动条,暗示是否有可滚动的内容。可以在ViewDidAppear或[table reload]之后调用14、点击Cell中的按钮时,如何取所在的Cell
-(void)OnTouchBtnInCell:(UIButton *)btn { CGPoint point = btn.center; point = [table convertPoint:point fromView:btn.superview]; NSIndexPath* indexpath = [table indexPathForRowAtPoint:point]; UITableViewCell *cell = [table cellForRowAtIndexPath:indexpath]; ... // 也可以通过一路取btn的父窗口取到cell,但如果cell下通过好几层subview才到btn,就要取好几次 superview // 所以我用上面的方法,比较通用。这种 方法也适用于其它控件。 }
15、deselectRowAtIndexPath的作用
有没有遇到过,导航+UITableView,在push,back回来之后,当前cell仍然是选中的状态。当然,解决办法简单,添加一句[tableView deselectRowAtIndexPath:indexPath animated:YES]即可。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; // 不加此句时,在二级栏目点击返回时,此行会由选中状态慢慢变成非选中状态。 // 加上此句,返回时直接就是非选中状态 }
相关文章推荐
- UITableView学习笔记
- UITableView学习笔记
- UITableView学习笔记
- UITableView学习笔记
- UITableView学习笔记
- UITableView学习笔记
- UITableView学习笔记
- Objective - C UITableView学习笔记
- UITableView学习笔记
- UITableView学习笔记
- UITableView学习笔记
- UITableView学习笔记
- iOS中UITableView学习笔记(一)
- UITableView学习笔记
- UITableView学习笔记
- iOS中UITableView学习笔记(二)之cell重用
- UITableView学习笔记
- UITableView学习笔记
- UITableView学习笔记
- UITableView学习笔记