zoukankan      html  css  js  c++  java
  • 自定义UITableViewCell中的button实现视图切换

    自定义UITableViewCell中的button如何实现视图切换 

    问题如题,原理很简单,只要在cell中给对应的button添加操作事件就好了。

    示例代码如下:

    navigationTableCell.h

    //
    //  navigationTableCell.h
    //  xunYi7
    //
    //  Created by david on 13-6-18.
    //  Copyright (c) 2013年 david. All rights reserved.
    //
    #import <UIKit/UIKit.h>
    @interface navigationTableCell : UITableViewCell
    @property (strong, nonatomic) IBOutlet UIButton *directorBtn;
    @property (strong, nonatomic) IBOutlet UIButton *writerBtn;
    @property (strong, nonatomic) IBOutlet UIButton *performerBtn;
    @property (strong, nonatomic) IBOutlet UIButton *otherBtn;
    @property (strong, nonatomic) IBOutlet UIButton *chancePerformerBtn;
    @property (strong, nonatomic) IBOutlet UIButton *chanceOtherBtn;
    @end

    navigationTableCell.m

    //
    //  navigationTableCell.m
    //  xunYi7
    //
    //  Created by david on 13-6-18.
    //  Copyright (c) 2013年 david. All rights reserved.
    //
    #import "navigationTableCell.h"
    @implementation navigationTableCell
    - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
    {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
    // Initialization code
    }
    return self;
    }
    - (void)setSelected:(BOOL)selected animated:(BOOL)animated
    {
    [super setSelected:selected animated:animated];
    // Configure the view for the selected state
    }
    @end
    
    功能实现过程

    -(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    NSUInteger row = [indexPath row];
    if(row == 0)
    {
    static NSString *navigationTableCellIdentifier = @"navigationTableCell";
    UINib *navigationTableCellNib = [UINib nibWithNibName:@"navigationTableCell" bundle:nil];
    [_dataTable registerNib:navigationTableCellNib forCellReuseIdentifier:navigationTableCellIdentifier];
    navigationTableCell *cell = [self.dataTable dequeueReusableCellWithIdentifier:navigationTableCellIdentifier];
    if(cell == nil)
    {
    cell = [[navigationTableCell alloc] initWithStyle:UITableViewCellStyleDefault
    reuseIdentifier:navigationTableCellIdentifier];
    }
    [cell.directorBtn addTarget:self
    action:@selector(directorPush:)
    forControlEvents:UIControlEventTouchUpInside];
    [self giveButtonDrawCorner:cell.directorBtn];
    [cell.writerBtn addTarget:self
    action:@selector(writerPush:)
    forControlEvents:UIControlEventTouchUpInside];
    [self giveButtonDrawCorner:cell.writerBtn];
    [cell.performerBtn addTarget:self
    action:@selector(performerPush:)
    forControlEvents:UIControlEventTouchUpInside];
    [self giveButtonDrawCorner:cell.performerBtn];
    [cell.otherBtn addTarget:self
    action:@selector(otherPush:)
    forControlEvents:UIControlEventTouchUpInside];
    [self giveButtonDrawCorner:cell.otherBtn];
    [cell.chancePerformerBtn addTarget:self
    action:@selector(chancePerformerPush:)
    forControlEvents:UIControlEventTouchUpInside];
    [self giveButtonDrawCorner:cell.chancePerformerBtn];
    [cell.chanceOtherBtn addTarget:self
    action:@selector(chanceOtherPush:)
    forControlEvents:UIControlEventTouchUpInside];
    [self giveButtonDrawCorner:cell.chanceOtherBtn];
    return cell;
    }
    static NSString *cellIdentifier = @"cellIdentifier";
    UITableViewCell *cell = [self.dataTable dequeueReusableCellWithIdentifier:cellIdentifier];
    if(cell == nil)
    {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    NSDictionary *dic = [self.dataDic objectForKey:[NSString stringWithFormat:@"%d",row]];
    CGRect cellFrame = [cell frame];
    cellFrame.size.height = 50.0;
    [cell setFrame:cellFrame];
    cell.textLabel.text = [dic valueForKey:@"title"];
    cell.textLabel.font = [UIFont systemFontOfSize:18.0];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
    }
  • 相关阅读:
    STL标准库algorithm中remove()函数的一个小注意事项
    关于 mem_fun_ref 和 bind2nd的疑问
    记录昨日程序调不通的解释
    复习几个C++概念:声明与定义、传值与拷贝构造、初始化和赋值
    对stl map 赋值添加元素的疑惑 求解(管理员让这个帖子多见会人吧~~谢谢啦!)
    摘抄书上一个逆序字符串的例子(可根据不同的符号,比如*&,.;来拆分单词)
    “指向指针的引用”小例子:忽然豁然开朗~
    论文 “tracking evolving communities in large linked networks” 中不懂的问题和知识总结
    [wp7软件]wp7~~时间日程 软件大全! 集合贴~~~
    [wp7游戏]wp7~~超级血腥类游戏~~集合贴~~
  • 原文地址:https://www.cnblogs.com/chengfang/p/4113484.html
Copyright © 2011-2022 走看看