TableView

简介: TableView
#pragma mark ---- TableView开始
//
// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [JDList count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
   return 88;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"ListCell";
    ListCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[ListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    cell = [[[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil] lastObject];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;  
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
#pragma mark ---- TableView结束

不等高

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
    return cell.frame.size.height;
}

直接cell.xib

  NSArray* nibView =  [[NSBundle mainBundle] loadNibNamed:@"ManagerTileCell" owner:nil options:nil];
    UITableViewCell *cell = [nibView objectAtIndex:0];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
self.tableView.tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];

设置Cell不可点击

self.m_table.allowsSelection =NO;

设置Cell点击后不变色

cell.selectionStyle =UITableViewCellSelectionStyleNone;
滑动删除
//先要设Cell可编辑
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.section==0)
        return NO;
    else
        return YES;
}
//定义编辑样式
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleDelete;
}
//进入编辑模式,按下出现的编辑按钮后
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    id obj = [self.dataList objectAtIndex:indexPath.row];
    if([obj isKindOfClass:[NearChatNode class]])
    {
        NearChatNode *nearmsg = obj;
        NSString *sql = [NSString stringWithFormat:@"delete from chatHis  where msgFromUid='%@' or msgToUid='%@';DELETE from chatNearHis where myid='%@' or other='%@';",nearmsg.vo_id,nearmsg.vo_id,nearmsg.vo_id,nearmsg.vo_id];
        [g_data.sqlite NSSendSql:sql];
        [self notiRefreshMyMsg];
    }
}
相关文章
|
3月前
|
开发者 iOS开发
介绍 UITableView 和 UICollectionView,它们的区别是什么?
介绍 UITableView 和 UICollectionView,它们的区别是什么?
58 0
UITableViewCell和UICollectionViewCell自适应高度
UITableView和UICollectionView想通,此处就已UITableView为例
185 0
UITableViewCell和UICollectionViewCell自适应高度
UITableView使用中的一些刁专问题总结
tableview中cell的系统分隔线问题(分隔线顶满或者缩短)
UITableView使用中的一些刁专问题总结
UITableView的创建
UITableView的创建
75 0
UICollectionview的使用详解
三个代理<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout> 前两个的用法和tableView的很像,第三个是布局的协议。(注意:头视图尾视图都是由代理方法获得,而且需要写注册,缺少了也不行。) 注册以后,就不需要再去管理复用的问题了。这点就很简单。这个如果用好的话,会非常的简单。