自定义UITableViewCell

//引入头文件

#import "Cell.h"


//修改方法

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath

{

    static NSString *CellIdentifier = @"Cell";

    Cell *cell = (Cell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CellView" owner:self options:nil];

        cell = [nib objectAtIndex:0];

    }

    NSInteger row = [indexPath row];

    //cell.textLabel.text =[listData objectAtIndex:row];

    cell.colorLabel.text = [listData objectAtIndex:row];

    cell.nameLabel.text = [listData objectAtIndex:row];

    return cell;

}


二种

 

    static BOOL nibsRegistered = NO;

    if (!nibsRegistered) {

        UINib *nib = [UINib nibWithNibName:@"CustomsCell" bundle:nil];

        [tableView registerNib:nib forCellReuseIdentifier:indetify];

        nibsRegistered = YES;

    }

    if (cell==nil) {

        cell=[[CustomsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indetify];

    }



设置高度

 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 90;

}


//

缩进级别

 

- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath{

    NSInteger row = [indexPath row];

    if (row == 2) {

        return 1;

    }else

    return 10;

}


 

#pragma mark TableView Delegate

//对编辑的状态下提交的事件响应

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

{

    NSLog(@"commond eidting style ");

    if (editingStyle == UITableViewCellEditingStyleDelete) { 

        [dataArray removeObjectAtIndex:indexPath.row]; 

        // Delete the row from the data source. 

        [tableview deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 

        

    }    

    else if (editingStyle == UITableViewCellEditingStyleInsert) { 

        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view. 

    }    

}


//响应选中事件

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    NSLog(@"did selectrow");

}

//行将显示的时候调用

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

{

    NSLog(@"will display cell");

    

}

//点击了附加图标时执行

-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath

{

    NSLog(@"accessoryButtonTappedForRowWithIndexPath");

}


//开始移动row时执行

-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath*)destinationIndexPath

{

    NSLog(@"moveRowAtIndexPath");

}


//开发可以编辑时执行

-(void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath

{

    NSLog(@"willBeginEditingRowAtIndexPath");

}

//选中之前执行

-(NSIndexPath*)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    NSLog(@"willSelectRowAtIndexPath");

    return indexPath;

}

//将取消选中时执行

-(NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath

{

     NSLog(@"willDeselectRowAtIndexPath");

    return indexPath;

}

//移动row时执行

-(NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath

{

     NSLog(@"targetIndexPathForMoveFromRowAtIndexPath");

    //用于限制只在当前section下面才可以移动

    if(sourceIndexPath.section != proposedDestinationIndexPath.section){

        return sourceIndexPath;

    }

 

    return proposedDestinationIndexPath;

}


//删除按钮的名字

-(NSString*)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath

{

    return @"删除按钮的名字";

}


//让表格可以修改,滑动可以修改

-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath

{

    return YES;

}


//让行可以移动

-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath

{

    return YES;

}


-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

{

    //

    NSLog(@"手指撮动了");

    return UITableViewCellEditingStyleDelete;

}


#pragma mark TableView DataSource

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    return 1;

}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return [dataArray count];

}

 

 

 


//1.设置背景图片
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background"]];
  //2.设置cell透明度
cell.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.3];


    table.backgroundView = [[UIImageView alloc]initWithImage:[UIImageimageNamed:@"background.jpg"]];

    table.backgroundView.alpha = 0.5;


//添加钩子


 

    NSInteger row = [indexPath row];

    if (indexPath.section == 1) {

    cell.textLabel.text = [themes objectAtIndex:row];

        NSInteger row = [indexPath row];

        NSInteger oldRow = [lastIndexPath row];

        cell.accessoryType = (row == oldRow && lastIndexPath != nil) ?

        UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;


---------

 

        int newRow = [indexPath row];

        int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;

        

        if (newRow != oldRow)

        {

            UITableViewCell *newCell = [tableView cellForRowAtIndexPath:

                                        indexPath];

            newCell.accessoryType = UITableViewCellAccessoryCheckmark;

            

            UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:

                                        lastIndexPath];

            oldCell.accessoryType = UITableViewCellAccessoryNone;

            lastIndexPath = [indexPath retain];

            //self.lastIndexPath = indexPath;

        }

        

        [tableView deselectRowAtIndexPath:indexPath animated:YES];



//取消选中


 

[self performSelector:@selector(delectCell:) withObject:nil afterDelay:0.1];

--------------

 

- (void) delectCell:(id)sender{

    [settingTable deselectRowAtIndexPath:[settingTable indexPathForSelectedRow] animated:YES];

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值