1.1 "TableCell.h"
#import <UIKit/UIKit.h>
/**
* 房间桌子显示结构
* /
@interface TableCell : UITableViewCell {
UILabel *tableNoLable// 桌子号
UIImageView *tableImageView// 桌子图片
UIImageView *tableStateImageView// 桌子状态图片
}
@property (nonatomic ,retain) IBOutlet UILabel *tableNoLable// 桌子号
@property (nonatomic ,retain) IBOutlet UIImageView *tableImageView// 桌子图片
@property (nonatomic ,retain) IBOutlet UIImageView *tableStateImageView// 桌子状态图片
1.2 TableCell. m
#import "TableCell.h"
@implementation TableCell
@synthesize tableNoLable// 桌子号
@synthesize tableImageView// 桌子图片
@synthesize tableStateImageView// 桌子状态图片
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
// Initialization code
}
return self
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated]
// Configure the view for the selected state
}
- (void)dealloc {
[tableNoLable release]
[tableImageView release]
[hand3ImageView release]
[super dealloc]
}
@end
1.3 布置布局文件( xib 文件)指明 class 为自己定义的 tabelcellview
new 一个Empty Xib文件,其中不包含view, 在libriary中拖一个UITableCell到两个图标的框中,双击cellview,指明class为cell.m文件,开始编辑
2. 页面中在 tableView 中加载自己的 cell
#import "TableCell.h"
// 设置房间桌子数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
[Util showLog:@"numberOfRowsInSection"]
return g_Room.wTableCount
}
// 设置单元格的高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
[Util showLog:@"heightForRowAtIndexPath"]
return kTableViewRowHeight
}
// 设置单元个样式
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
[Util showLog:@"cellForRowAtIndexPath start"]
static NSString *tableCellIdentifier = @"TableCellIdentifier"
TableCell *cell = (TableCell *)[tableView dequeueReusableCellWithIdentifier:tableCellIdentifier]
[Util showLog:@"TableCellIdentifier"]
if(cell == nil){
NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"TableCell" owner:self options:nil]
for(id oneObject in nib){
if([oneObject isKindOfClass:[TableCell class]]){
cell = (TableCell *)oneObject
//***** 自己设计每个 cell 的内容,此函数会回调 table 的行数次,行数为 numberOfRowsInSection:(NSInteger)section 函数指定
// 显示桌子号码
NSUInteger row = [indexPath row] + 1
NSString *str =[NSString stringWithFormat:@"%d",row]
cell.tableNoLable.text = [[@" 第 " stringByAppendingString:str] stringByAppendingString:@" 桌 "]
[Util showLog:@"tableNoLable"]
if(deskshowFlg){
// 获取要绘画的桌子信息
Desk *tempDesk = [g_DeskArray objectAtIndex:[indexPath row]]
}
}
}
一种方式给Button加上tag值:这里分为两种:一种是直接在原生的UITableViewCell上添加UIButton按钮,然后给UIButton设置tag值,然后在控制器里的方法里通过取数据,做界面跳转等。还是举个例子吧,省的回忆半天。[objc]view plaincopy
- (UITableViewCell*)tableView:(UITableView*)tableViewcellForRowAtIndexPath:(NSIndexPath*)indexPath
{
staticNSString*identifier =@"Cell"
UITableViewCell*cell = [tableViewdequeueReusableCellWithIdentifier:reuseIdentifier]
if(cell ==nil) {
cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:identifier]
cell.selectionStyle= UITableViewCellSelectionStyleNone
}
User*user = _users[indexPath.row]
cell.user= user
//拍照button
UIButton *photographButton = [UIButtonbuttonWithType:UIButtonTypeCustom]
photographButton.frame= CGRectMake(221,10,100,44)
[photographButtonsetImage:[UIImageimageNamed:@"camera.png"]forState:UIControlStateNormal]
[photographButtonaddTarget:selfaction:@selector(photographButtonClicked:)forControlEvents:UIControlEventTouchUpInside]
photographButton.tag= indexPath.row
[cell.contentViewaddSubview:photographButton]
returncell
}
然后在点击事件中取数据,加信息
[objc]view plaincopy
- (void)photographButtonClicked:(UIButton*)sender{
User*user = _users[sender.tag]
PhotoPickerController*photoPicker = [[PhotoPickerControlleralloc]init]
photoPicker.user= user
[self.navigationControllerpushViewController:photoPickeranimated:YES]
}
根据tag值进行获取,在这里设置tag值, 然后在方法 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 中进行获取这个tag值,获取方法是: UIButton *exitBtn = (UIButton *)[cell viewWithTag:1]//1是我上面设置的tag值 这样就获取到了,你再给他添加action事件就可以了,欢迎分享,转载请注明来源:内存溢出
评论列表(0条)