ios uitableviewcell怎样设置有数据的单元格有分隔线没数据的

Pages: 1/4
主题 : 怎样让UITableView的分割线从最左边开始绘制
级别: 骑士
可可豆: 1000 CB
威望: 1000 点
在线时间: 217(时)
发自: Web Page
怎样让UITableView的分割线从最左边开始绘制&&&
rt,UITableView的分割线在左边是空白的,如附件所示,貌似这是UITableView特性,不能改。
图片:屏幕快照
上午10.49.28.png
UID: 83747
发帖: 3855
可可豆: 19515 CB
威望: 19386 点
在线时间: 2363(时)
发自: Web Page
iOS7以后默认就这样了。如果你非要从最左侧开始,只能去掉默认的,自己画了。
级别: 骑士
可可豆: 1000 CB
威望: 1000 点
在线时间: 217(时)
发自: Web Page
回 1楼(chenxin) 的帖子
感觉很丑,苹果的品味降低了
级别: 精灵王
UID: 34556
发帖: 1218
可可豆: 919 CB
威望: 1985 点
在线时间: 1297(时)
发自: Web Page
把分隔线 去 掉 自定义多好
级别: 侠客
UID: 153346
可可豆: 353 CB
威望: 325 点
在线时间: 1127(时)
发自: Web Page
回 楼主(osmanthus) 的帖子
if (isHighIOS7) {&&&&&&&&[_chatTable setSeparatorInset:UIEdgeInsetsMake(0, 67, 0, 0)];&&&&}楼主试试这个,把那个67改成负数,应该可行。我最近用的把线收紧,你要拉通,改那个应该行。这是IOS7出来的属性。
级别: 新手上路
UID: 239112
可可豆: 510 CB
威望: 234 点
在线时间: 94(时)
发自: Web Page
我只是来看解决方法的。4楼应该可行吧
我是小明,我为自己带盐..
级别: 骑士
可可豆: 1000 CB
威望: 1000 点
在线时间: 217(时)
发自: Web Page
回 4楼(e1784923) 的帖子
多谢,我试了还是no行啊,算了,我还是去掉分割线,自定义cell。
级别: 侠客
UID: 219269
可可豆: 2440 CB
威望: 1457 点
在线时间: 444(时)
发自: Web Page
setSeparatorInset&& 设置tableview的separatorInset 为UIEdgeInsetsZero
级别: 骑士
可可豆: 1000 CB
威望: 1000 点
在线时间: 217(时)
发自: Web Page
回 7楼(yuhongde) 的帖子
级别: 骑士
可可豆: 1000 CB
威望: 1000 点
在线时间: 217(时)
发自: Web Page
回 7楼(yuhongde) 的帖子
实测真的可以
Pages: 1/4
关注本帖(如果有新回复会站内信通知您)
4*5+2 正确答案:22
发帖、回帖都会得到可观的积分奖励。
按"Ctrl+Enter"直接提交
关注CocoaChina
关注微信 每日推荐
扫一扫 浏览移动版21826人阅读
iphone(78)
第一种方法
-(void)setExtraCellLineHidden: (UITableView *)tableView
&&&&UIView *view = [UIView new];
&&&&view.backgroundColor = [UIColor clearColor];
&&&&[tableView setTableFooterView:view];
&&&&[view release];
- (void)viewDidLoad
& & [super&viewDidLoad];
& & //设置tableView不能滚动
& & [self.tableView&setScrollEnabled:NO];
& & //在此处调用一下就可以啦 :此处假设tableView的name叫:tableView
& & [self&setExtraCellLineHidden:self.tableView];
在iOS4.3和iOS5.0中通过:值得注意的是在iOS4.3中可以直接设置footer为nil,但是在5.0不行,因为UITableView会默认生成一个Footer。(详见iOS Release Notes中的说明:Returning nil from the tableView:viewForHeaderInSection: method (or its footer equivalent) is no longer sufficient to
hide a header. You must override tableView:heightForHeaderInSection: and return 0.0 to hide a header.)
plain类型的tableview当显示的数据很少时,下面的cell即使不显示数据也会有分割线,可以通过下面这个函数去掉多余的分割线。
- (void)setExtraCellLineHidden: (UITableView&*)tableView
& &&UIView&*view =[ [UIView&alloc]init];
& & view.backgroundColor&= [UIColor&clearColor];
& & [tableView&setTableFooterView:view];
& & [view&release];
当tableview的dataSource为空时,也就是没有数据可显示时,该方法无效,只能在numberOfRowsInsection函数,通过判断dataSouce的数据个数,如果为零可以将tableview的separatorStyle设置为UITableViewCellSeparatorStyleNone去掉分割线,然后在大于零时将其设置为
UITableViewCellSeparatorStyleSingleLine
第二种方法
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
// Drawing our own separatorLine here because I need to turn it off for the
// last row. I can only do that on the tableView and on on specific cells.
// The y position below has to be 1 less than the cell height to keep it from
// disappearing when the tableView is scrolled.
UIImageView *separatorLine = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, cell.frame.size.height - 1.0f, cell.frame.size.width, 1.0f)];
separatorLine.image = [[UIImage imageNamed:@&grayDot&] stretchableImageWithLeftCapWidth:1 topCapHeight:0];
separatorLine.tag = 4;
[cell.contentView addSubview:separatorLine];
[separatorLine release];
// Setup default cell setttings.
UIImageView *separatorLine = (UIImageView *)[cell viewWithTag:4];
separatorLine.hidden = NO;
// In the cell I want to hide the line, I just hide it.
seperatorLine.hidden = YES;
In viewDidLoad:
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:501121次
积分:4893
积分:4893
排名:第3784名
原创:79篇
转载:51篇
评论:44条
(1)(1)(1)(4)(1)(3)(1)(3)(1)(2)(8)(3)(3)(6)(8)(6)(4)(7)(44)(11)(3)(3)(4)iOS- 显示数据列表最常用的一个控件UITableView
相信做过iOS的程序员,最熟悉的控件一定少不了UITableView,最常用的控件也一定少不了UITableView!
今天分享一下自己对UITableView的实现大体思路,和整理出来的学习笔记!
1.UITableView里的结构图                       
2.UITableView数据展示的条件                      
1& UITableView的所有数据都是由数据源(dataSource)提供的,所以要想在UITableView展示数据,必须设置UITableView的dataSource数据源对象
2& 要想当UITableView的dataSource对象,必须遵守UITableViewDataSource协议,实现相应的数据源方法
3& 当UITableView想要展示数据的时候,就会给数据源发送消息(调用数据源方法),UITableView会根据方法返回值决定展示怎样的数据
3.数据展示的过程                             
数据显示,三步走
1& 先调用数据源的
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
得知一共有多少组
2& 然后调用数据源的
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
得知第section组一共有多少行
3& 然后调用数据源的
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
得知第indexPath.section组 第indexPath.row 行显示怎样的cell(显示什么内容)
4.开发中经常用到的UITableView数据源方法               
1& 一共有多少组
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
@required &2.3 是必须实现
2& 第section组一共有多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
3& 第indexPath.section组 第indexPath.row行显示怎样的cell(显示什么内容)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
4& 第section组显示怎样的头部标题
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)
5& 第section组显示怎样的尾部标题
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)
5.开发中经常用到的UITableView代理方法               
1.- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
选中了UITableView的某一行
2.- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
某一行的高度
3.- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
第section分区头部的高度
4.- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
第section分区尾部的高度
5.- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
第section分区头部显示的视图
6.- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
第section分区尾部显示的视图
7.- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath
设置每一行的等级缩进(数字越小,等级越高)
6.tableView刷新数据的方式                      
&1& 修改模型数据
&2& 刷新表格
- reloadData
整体刷新(每一行都会刷新)
&- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
(window.slotbydup=window.slotbydup || []).push({
id: '2467140',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467141',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467143',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467148',
container: s,
size: '1000,90',
display: 'inlay-fix'ios之UITableViewController(二)tableView的编辑模式_iOS开发_
ios之UITableViewController(二)tableView的编辑模式
来源:人气:1025
tableView的编辑模式
&& 表视图可以进入编辑模式,当进入编辑模式就可以进行删除、插入、移动单元等操作
& 效果图:
&& 让表视图进入编辑模式,进入编辑模式的方法有两种,一种是使用导航栏的edit&
&&&& 按钮,另一种是设置tableView的editing属性进入编辑模式。
&&&& 最后通过实现UITableViewDataSource协议的方法实现单元格的删除、插入和移动
1,在viewDidLoad方法里面指定导航栏的右按钮为edit按钮
& self.navigationItem.rightBarButtonItem&=self.editButtonI
&2,另一种进入编辑模式的方式是修改tableView的editing属性
& 该属性是一个BOOL类型,默认值是NO,这里给导航栏添加一个左按钮,通过点击左按钮修改editing属性的值
&& 进入和退出编辑模式
-&(void)editTableView:(UIBarButtonItem&*)button
  //修改editing属性的值,进入或退出编辑模式
&&&&& [self.tableView&setEditing:!self.tableView.editinganimated:YES];
&  if(self.tableView.editing){
  &button.title&=&@"完成";
&  button.title&=&@"编辑";
实现删除和插入行
  两方法一响应
方法一:那些行进入编辑模式
-&(BOOL)tableView:(UITableView&*)tableView&canEditRowAtIndexPath:(NSIndexPath&*)indexPath
&&&&return&YES;
方法二:进入编辑模式的cell是删除还是增加
-(UITableViewCellEditingStyle)tableView:(UITableView&*)tableView&editingStyleForRowAtIndexPath:(NSIndexPath&*)indexPath
&&&&return&UITableViewCellEditingStyleD
注意:这个方法里一般返回两种类型,还有一中默认类型
删除:UITableViewCellEditingStyleDelete
增加:UITableViewCellEditingStyleInsert
响应:点击当点击delete后执行的删除过程
-(void)tableView:(UITableView&*)tableView&commitEditingStyle:(UITableViewCellEditingStyle)editingStyle&forRowAtIndexPath:(NSIndexPath&*)indexPath
  //删除数据源里的数据
  [self.array&removeObjectAtIndex:indexPath.row];
  //再删除tableView中对应的行
&&& &[tableView&deleteRowsAtIndexPaths:@[indexPath]&withRowAnimation:UITableViewRowAnimationFade];
注意:先除数据源里的数据,删除tableView中对应的行
实现移动行
& 当tableView进入编辑模式之后,默认每一行都是可以移动,每一行尾部有一个图标
  为三行灰色横线的按钮,就是表示该行可以移动
&一方法一响应
方法一:那些cell可以移动
-(BOOL)tableView:(UITableView&*)tableView
canMoveRowAtIndexPath:(NSIndexPath&*)indexPath
&&&&return&YES;
响应:移动的具体操作
-&(void)tableView:(UITableView&*)tableView
moveRowAtIndexPath:(NSIndexPath&*)fromIndexPath
&&&&&&toIndexPath:(NSIndexPath&*)toIndexPath
&&&&TRStudent&*stu=self.array[fromIndexPath.row];
&&&&[self.array&removeObjectAtIndex:fromIndexPath.row];
&&&&[self.array&insertObject:stuatIndex:toIndexPath.row];
AppDelegate.h
#import&&UIKit/UIKit.h&
@interface&AppDelegate&:&UIResponder&&UIDelegate&
@operty&(strong,&nonatomic)&UIWindow&*
AppDelegate.m
#import&"AppDelegate.h"
#import"TRStudent.h"
#import&"TRTableViewController.h"
@implementation&AppDelegate
&-&(BOOL)application:(UIApplication&*)application&didFinishLaunchingWithOptions:(NSDictionary&*)launchOptions
&&&&self.window&=&[[UIWindow&alloc]&initWithFrame:[[UIScreen&mainScreen]&bounds]];
&&&&//&Override&point&for&customization&after&application&launch.
&&&&self.window.backgroundColor&=&[UIColor&whiteColor];
&&&&TRTableViewController&*tr1=[[TRTableViewController&alloc]&initWithNibName:@"TRTableViewController"&bundle:nil];
&&&&UINavigationController&*navi=[[UINavigationController&alloc]&initWithRootViewController:tr1];
&&&&self.window.rootViewController=
&&&&[self.window&makeKeyAndVisible];
&&&&return&YES;
TRTableViewController.h
#import&&UIKit/UIKit.h&
@interface&TRTableViewController&:&UITableViewController
@property(nonatomic,strong)&NSMutableArray&*
TRTableViewController.m
#import&"TRTableViewController.h"
#import&"TRStudent.h"
@interface&TRTableViewController&()
@implementation&TRTableViewController
-(id)initWithNibName:(NSString&*)nibNameOrNil&bundle:(NSBundle&*)nibBundleOrNil
&&&&return&self=[super&initWithNibName:nibNameOrNil&bundle:nibBundleOrNil];
-&(void)viewDidLoad
&&&&[super&viewDidLoad];
&&&&self.array=[TRStudent&getarray];
&&&&self.navigationItem.rightBarButtonItem=self.editButtonI
//有多少分区
-&(NSInteger)numberOfSectionsInTableView:(UITableView&*)tableView
&&&&return&1;
//有多少个cell单元
-&(NSInteger)tableView:(UITableView&*)tableView&numberOfRowsInSection:(NSInteger)section
&&&&return&self.array.
//cell单元
-&(UITableViewCell&*)tableView:(UITableView&*)tableView&cellForRowAtIndexPath:(NSIndexPath&*)indexPath
&&&&UITableViewCell&*cell&=&[tableView&dequeueReusableCellWithIdentifier:@"cell"];
&&&&if(cell==nil)
&&&&&&&&cell=[[UITableViewCell&alloc]&initWithStyle:UITableViewCellStyleValue1&reuseIdentifier:@"cell"];
&&&&TRStudent&*stu=self.array[indexPath.row];
&&&&cell.textLabel.text=stu.
&&&&return&
//那些行进入编辑模式,根据你的需求自行设置,我这里设置的全部
-&(BOOL)tableView:(UITableView&*)tableView&canEditRowAtIndexPath:(NSIndexPath&*)indexPath
&&&&return&YES;
//进入编辑模式的cell是删除还是增加
//自行设置,我这里设置的是最后一个cell单元是增加,其他是删除
-(UITableViewCellEditingStyle)tableView:(UITableView&*)tableView
&&&&&&&&&&editingStyleForRowAtIndexPath:(NSIndexPath&*)indexPath
&&&&if(indexPath.row==self.array.count-1)
&&&&&&&&return&UITableViewCellEditingStyleI
&&&&return&UITableViewCellEditingStyleD
//点击当点击delete后执行的删除增加过程
-&(void)tableView:(UITableView&*)tableView&commitEditingStyle:(UITableViewCellEditingStyle)editingStyle&forRowAtIndexPath:(NSIndexPath&*)indexPath
&&&&if&(editingStyle&==&UITableViewCellEditingStyleDelete)&{
&&&&&&&&&&&&[self.array&removeObjectAtIndex:indexPath.row];
&&&&&&&&[tableView&deleteRowsAtIndexPaths:@[indexPath]&withRowAnimation:UITableViewRowAnimationFade];
&&&&}&else&if&(editingStyle&==&UITableViewCellEditingStyleInsert)&{
&&&&&&&&TRStudent&*str2=[[TRStudent&alloc]&init];
&&&&&&&&str2.name=@"qwer";
&&&&&&&&str2.name=@"124456";
&&&&&&&&[self.array&addObject:str2];
&&&&&&&&NSIndexPath&*insetindexpath=[NSIndexPath&indexPathForRow:self.array.count-1&inSection:0];
&&&&&&&&[tableView&insertRowsAtIndexPaths:@[insetindexpath]&withRowAnimation:UITableViewRowAnimationAutomatic];
//那些cell可移动
-(BOOL)tableView:(UITableView&*)tableView
canMoveRowAtIndexPath:(NSIndexPath&*)indexPath
&&&&return&YES;
-&(void)tableView:(UITableView&*)tableView
moveRowAtIndexPath:(NSIndexPath&*)fromIndexPath
&&&&&&toIndexPath:(NSIndexPath&*)toIndexPath
&&&&TRStudent&*stu=self.array[fromIndexPath.row];
&&&&[self.array&removeObjectAtIndex:fromIndexPath.row];
&&&&[self.array&insertObject:stuatIndex:toIndexPath.row];
TRStudent.h
#import&&Foundation/Foundation.h&
&@interface&TRStudent&:&NSObject
@property(nonatomic,strong)&NSString&*
@property(nonatomic,strong)&NSString&*
+(NSMutableArray&*)
TRStudent.m
#import&"TRStudent.h"
@implementation&TRStudent
+(NSMutableArray&*)getarray
&&&&TRStudent&*stu1=[[TRStudent&alloc]&init];
&&&&stu1.name=@"q";
&&&&stu1.phone=@"12345";
&&&&TRStudent&*stu2=[[TRStudent&alloc]&init];
&&&&stu2.name=@"w";
&&&&stu2.phone=@"12345";
&&&&TRStudent&*stu3=[[TRStudent&alloc]&init];
&&&&stu3.name=@"sdsq";
&&&&stu3.phone=@"12345";
&&&&NSMutableArray&*mut=[[NSMutableArray&alloc]&init];
&&&&[mut&addObject:stu1];
&&&&[mut&addObject:stu2];
&&&&[mut&addObject:stu3];
&&&&return&
优质网站模板&/pre&&pre name=&code& class=&objc&&first method:
- (void)viewDidLoad{
[super viewDidLoad];
//此处写入让其不显示下划线的代码
self.tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];`
sencond method:
[super viewDidLoad];
//此处写入让其不显示下划线的代码
self.tableView.tableFooterView = [[UIView alloc]init];
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:2195次
排名:千里之外
原创:20篇
(2)(3)(2)(1)(4)(9)

我要回帖

更多关于 ios 继承uitableview 的文章

 

随机推荐