本文介绍了如何在自定义表格视图单元格中添加复选框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我的自定义 UITableViewCell 中创建自定义复选框.我在 UITableViewCell
中使用了以下方式,但觉得不合适.我需要从 cellForRowAtIndexPath
I want to create custom check box in my Custom UITableViewCell. I have used following way in UITableViewCell
but doesn't find it appropriate. I need to it inside from cellForRowAtIndexPath
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
}
- (IBAction)ActionBtnSelect:(id)sender {
if ([[UIImage imageNamed:@"checkbox.png"] isEqual:BtnCheckBox.currentImage] || [[UIImage imageNamed:@"uncheckbox.png"] isEqual:BtnCheckBox.currentImage]) {
// do something
if (!bool_Select) {
[BtnCheckBox setImage:[UIImage imageNamed:@"checkbox.png"] forState:UIControlStateNormal];
bool_Select =YES;
}
else if (bool_Select) {
//NSLog(@"check box untick");
[BtnCheckBox setImage:[UIImage imageNamed:@"uncheckbox.png"] forState:UIControlStateNormal];
bool_Select =NO;
}
}else{
if (!bool_Select) {
[BtnCheckBox setImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateNormal];
bool_Select =YES;
}
else if (bool_Select) {
//NSLog(@"check box untick");
[BtnCheckBox setImage:[UIImage imageNamed:@"unchecked.png"] forState:UIControlStateNormal];
bool_Select =NO;
}
}
}
我想按照以下方式进行使用标签
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{---------------------------------
cell.BtnCheckBox.tag = indexPath.row;
[cell.BtnCheckBox addTarget:self action:@selector(ActionSingleSelect:) forControlEvents:UIControlEventTouchUpInside];
}
-(void)ActionSingleSelect:(UIButton*)button
{
}
推荐答案
cell.btn = [[UIButton alloc]init];
cell.btn.tag=indexPath.row;
[cell.btn addTarget:self action:@selector(ActionSingleSelect:) forControlEvents:UIControlEventTouchUpInside];
这篇关于如何在自定义表格视图单元格中添加复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!