设为首页 加入收藏

TOP

UITableView 基本使用方法总结(二)
2019-08-26 07:00:05 】 浏览:57
Tags:UITableView 基本 使用方法 总结
ection {
if (section == 0) { UIView* header = [[[NSBundle mainBundle] loadNibNamed: @"SettingHeaderView" owner: self options: nil] lastObject]; else { return nil; } }

(8)  - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath   当用户选中某个行的cell的时候,回调用这个。但是首先,必须设置tableview的一个属性为可以select 才行。

TableView.allowsSelection=YES;

如果不希望响应select,那么就可以用下面的代码设置属性:

cell.selectionStyle=UITableViewCellSelectionStyleBlue;

下面是响应select 点击函数,根据哪个section,哪个row 自己做出响应就好啦。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
    if (indexPath.section == 1) 
    {
        return;
    }
    else if(indexPath.section==0)
    {
        switch (indexPath.row) 
        {
            //聊天
            case 0:
            {
                [self  onTalkToFriendBtn];
            }
                break;
            default:
                break;
        }
    }
    else 
    {
        return ;
    }
}

如何让cell 能够响应 select,但是选中后的颜色又不发生改变呢,那么就设置    cell.selectionStyle = UITableViewCellSelectionStyleNone;

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //cell被选中后的颜色不变
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
}

(9)如何设置 tableview  每行之间的 分割线 

self.tableView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;

如果不需要分割线,那么就设置属性为 UITableViewCellSeparatorStyleNone  即可。

(10)如何设置 tableview cell的背景颜色

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     //设置背景颜色
     cell.contentView.backgroundColor=[UIColor colorWithRed:0.957 green:0.957 blue:0.957 alpha:1];

(11) - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath   这个函数响应,用户点击cell 右边的 箭头(如果有的话)

(12)如何设置tableview 可以被编辑 首先要进入编辑模式:

[TableView setEditing:YES animated:YES];

如果要退出编辑模式,肯定就是设置为NO

 - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath   返回当前cell  要执行的是哪种编辑,下面的代码是 返回 删除  模式

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleDelete;
}

 -(void) tableView:(UITableView *)aTableView commitEditingStyle:(UITableViewCellEditingStyle) editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath   通知告诉用户编辑了 哪个cell,对应上面的代码,我们在这个函数里面执行删除cell的操作。

-(void) tableView:(UITableView *)aTableView commitEditingStyle:(UITableViewCellEditingStyle) editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    [chatArray  removeObjectAtIndex:indexPath.row];
    [chatTableView  reloadData];
}

(13)如何获得 某一行的CELL对象   - (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath;

 

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇ios开发UI篇—UIScrollView属性及.. 下一篇UITapGestureRecognizer 的用法(..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目