码迷,mamicode.com
首页 > 其他好文 > 详细

UITableViewCell

时间:2015-08-06 21:47:22      阅读:99      评论:0      收藏:0      [点我收藏+]

标签:

1.Push跳转

技术分享
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellKey=@"cellKey";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellKey ];
    if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellKey];
    }
    NSString *content=[list objectAtIndex:indexPath.row];
    cell.textLabel.text=content;
    cell.accessoryType=UITableViewCellAccessoryDetailButton;
    
    return cell;
}

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
    NSString *content=[list objectAtIndex:indexPath.row];
    
    CellDetail *detail=[[CellDetail alloc]initWithNibName:@"CellDetail" bundle:[NSBundle mainBundle]];
    [self.navigationController pushViewController:detail animated:YES];
   // detail.label.text=[NSString stringWithFormat:@"我要去%@旅游",content];
    [detail setLabel:[NSString stringWithFormat:@"我要去%@旅游",content]];
}
View Code

2.打勾选中的样式

技术分享
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellKey=@"cellKey";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellKey];
    if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellKey];
        
    }
    cell.textLabel.text=[list objectAtIndex:indexPath.row];
    if (indexPath.row==markedIndexPath.row&&markedIndexPath) {
        cell.accessoryType=UITableViewCellAccessoryCheckmark;
    }
    else
    {
        cell.accessoryType=UITableViewCellAccessoryNone;
    }
    
    // Configure the cell...
    
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    self.markedIndexPath=indexPath;
    //[self.tableView reloadData];
    NSArray *array=[NSArray arrayWithObjects:indexPath, nil];
    [self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationFade];
    [self.tableView reloadData];
}
View Code

3.移动

技术分享
- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    
    
    NSMutableArray *array=[NSMutableArray arrayWithObjects:@"现代依兰特",@"法拉利612",@"路虎",@"标致",@"玛莎拉蒂",@"奥迪R8",@"美洲虎", nil];
    self.list=array;
    
    UIBarButtonItem *moveButton=[[UIBarButtonItem alloc]initWithTitle:@"移动" style:UIBarButtonItemStyleDone target:self action:@selector(Move)];
    self.navigationItem.rightBarButtonItem=moveButton;
}

- (void)Move
{
    [self.tableView setEditing:!self.tableView.editing animated:YES];
    if (self.tableView.editing) {
        [self.navigationItem.rightBarButtonItem setTitle:@"完成"];
    }
    else
    {
        [self.navigationItem.rightBarButtonItem setTitle:@"移动"];
    }
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //禁止编辑
    return  UITableViewCellEditingStyleNone;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
    NSString *car=[list objectAtIndex:sourceIndexPath.row];
    [list removeObjectAtIndex:sourceIndexPath.row];
    [list insertObject:car atIndex:destinationIndexPath.row];
}
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}
View Code

4.删除

技术分享
- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    
    NSMutableArray *array=[[NSMutableArray alloc]initWithObjects:@"牡丹花",@"莲花",@"含羞草",@"月季花",@"恐龙",@"",@"海参", nil];
    self.list=array;
    
    UIBarButtonItem *deleteButton=[[UIBarButtonItem alloc]initWithTitle:@"删除" style:UIBarButtonItemStyleBordered target:self action:@selector(Delete)];
    self.navigationItem.rightBarButtonItem=deleteButton;
}

- (void)Delete
{
    [self.tableView setEditing:!self.tableView.editing animated:YES];
    if (self.tableView.editing) {
        [self.navigationItem.rightBarButtonItem setTitle:@"完成"];
    }else
    {
        [self.navigationItem.rightBarButtonItem setTitle:@"删除"];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle==UITableViewCellEditingStyleDelete) {
        [list removeObjectAtIndex:indexPath.row];
        NSArray *array=[[NSArray alloc]initWithObjects:indexPath, nil];
        [tableView deleteRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationMiddle];
    }
}
View Code

 

UITableViewCell

标签:

原文地址:http://www.cnblogs.com/iOS-Code/p/4709131.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!