首页 > 代码库 > 自定义UITableViewCell中的button实现视图切换
自定义UITableViewCell中的button实现视图切换
自定义UITableViewCell中的button如何实现视图切换
原文地址: http://www.gowhich.com/blog/208
问题如题,原理很简单,只要在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:UITableViewCellStyleDefaultreuseIdentifier:navigationTableCellIdentifier];}[cell.directorBtn addTarget:selfaction:@selector(directorPush:)forControlEvents:UIControlEventTouchUpInside];[self giveButtonDrawCorner:cell.directorBtn];[cell.writerBtn addTarget:selfaction:@selector(writerPush:)forControlEvents:UIControlEventTouchUpInside];[self giveButtonDrawCorner:cell.writerBtn];[cell.performerBtn addTarget:selfaction:@selector(performerPush:)forControlEvents:UIControlEventTouchUpInside];[self giveButtonDrawCorner:cell.performerBtn];[cell.otherBtn addTarget:selfaction:@selector(otherPush:)forControlEvents:UIControlEventTouchUpInside];[self giveButtonDrawCorner:cell.otherBtn];[cell.chancePerformerBtn addTarget:selfaction:@selector(chancePerformerPush:)forControlEvents:UIControlEventTouchUpInside];[self giveButtonDrawCorner:cell.chancePerformerBtn];[cell.chanceOtherBtn addTarget:selfaction:@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;}
自定义UITableViewCell中的button实现视图切换
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。