动态调整cell高度
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
if (self.tweets) {
NSDictionary *tweet = (NSDictionary *)[self.tweets objectAtIndex:indexPath.row];
cell.textLabel.text = [NSString stringWithFormat:@"%@", [tweet objectForKey:@"text"]];
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.numberOfLines = 0;
cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:14.0];
}
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.tweets) {
NSDictionary *tweet = (NSDictionary *)[self.tweets objectAtIndex:indexPath.row];
NSString *cellText = [NSString stringWithFormat:@"%@", [tweet objectForKey:@"text"]];
UIFont *cellFont = [UIFont fontWithName:@"Helvetica" size:14.0];
CGSize constraintSize = CGSizeMake(280.0f, MAXFLOAT);
CGSize labelSize = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
return labelSize.height + 20;
}else{
return 20;
}
}
取消tableview 选中时的颜色
cell.selectionStyle = UITableViewCellSelectionStyleNone;
tableView 删除row 时要先删除datasource的数据
[self.fileList removeObjectAtIndex:indexPath.row];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationBottom];
TableView move cell的问题
一定要实现
禁用tableview cell的横扫 删除
- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.editing == NO || !indexPath) returnUITableViewCellEditingStyleNone; //this
if (indexPath.row == [datacount]) {
returnUITableViewCellEditingStyleInsert;
} else {
returnUITableViewCellEditingStyleDelete;
}
}
tableview 多选
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
}
关于如何取得所选择的行,两个办法1)通过delegate方法didselect和diddeselect来获取记录
2)通过运行时拿到UITableView的私有成员变量_selectedIndexPaths来获取
用第二种不会被封,但属于进阶用法,不建议新手使用。
xzzxz
分享到:
相关推荐
UITableView相关操作
UITableView的编辑,主要包括:cell的插入,删除,选择,移动排序以及UITableView的编辑模式等。
长按即可移动cell的UITableView
TTIndexBar 一个允许设置颜色的自定义UITableView索引
UITableview在编辑状态下的批量选择与左滑删除等相关功能的实现
SplittableViewKit - 当设备旋转时,UITableView中的IndexPath单元格将自动移动到左视图
主要介绍了iOS UITableView 与 UITableViewController实例详解的相关资料,非常不错,具有参考借鉴价值,需要的朋友可以参考下
UITableView嵌套滚动框架,swift3.0实现,简单易用,快速集成类似两个tableView嵌套滚动需求
主要介绍了Swift开发之UITableView状态切换效果的相关资料,非常不错,具有参考借鉴价值,需要的朋友可以参考下
PNChart是个界面很漂亮的图表第三方库,UITableView则不用过多介绍了,各位iOS开发者们都知道,下面这篇文章主要给大家介绍了关于iOS中PNChart与UITableView的联动的相关资料,需要的朋友可以参考下
只需一行代码,通过链式风格快速为UITableView创建Delegate和DataSource,满足你对UITableView的一切幻想
点击屏幕获取坐标点,不影响UITableView的事件,可以让UITableView相应Touch事件。重写UITableView的touch相关的方法,然后通过委托的方式提供给外部对象使用
主要介绍了IOS UITableView和NavigationBar的常用设置详解的相关资料,需要的朋友可以参考下
主要介绍了关于iOS利用UITableView设置全屏分隔线的几种方法的相关对比,分析这三种的各自优缺点,并且分享了设置UITableView的单元格分割线离屏幕左右的距离为0的方法,文中通过示例代码介绍的非常详细,需要的朋友...
EHFormKit 一个快速构造表单的工具 继承UITableView
ReverseExtension - UITableView扩展实现从表格底部插入单元格
看了一下,这里面都没有相关UITableView的滚动控制代码,自己就写了代码提交,以供大家参考; 思路是当数据加载量比较多的时候,会动画效果出现滚动按钮,方便你滚动到UITableView的顶部。
自定义iOS网格组件,基于UITableView 和 UICollectionView 构建的 GridView
主要介绍了ios8 UITableView设置 setSeparatorInset UIEdgeInsetsZero不起作用的解决办法(去掉15px空白间距)的相关资料,需要的朋友可以参考下
自动将选定的单元格滚动到可见区域,以向最终用户显示有关他/她感兴趣的单元格的完整信息,这不是很好吗? 我的意思是,无论如何,用户都将滚动这样的单元以查看整个内容,所以不应该将其自动滚动到可见区域是理想...