我正在做一个项目,但我坚持了一点。在单击单元格表视图后,我的项目有一个包含一些数据的表视图,它将扩展到部分。除了一件事我想设置一个复选框图像(当用户单击一个单元格时)之外,每一件事都很好。当我点击单元格时,它会给出单元格标题文本,但我无法在特定单元格部分设置复选框图像(如UITableViewCellAccessoryCheckmark)。
我在下面发布图像和代码:!
MyTableView 它包含根练习名称
这是扩展视图,我想要在单元格右侧的复选框(UITableViewCellAccessoryCheckmark)。
当我点击tableView didSelectRowAtIndexPath:它工作正常
//代码
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0) {
if ([indexPath isEqual:self.selectIndex]) {
self.isOpen = NO;
[self didSelectCellRowFirstDo:NO nextDo:NO];
self.selectIndex = nil;
}else
{
if (!self.selectIndex) {
self.selectIndex = indexPath;
[self didSelectCellRowFirstDo:YES nextDo:NO];
}else
{
[self didSelectCellRowFirstDo:NO nextDo:YES];
}
}
}else
{
NSDictionary *dic = [dataList objectAtIndex:indexPath.section];
NSArray *list = [dic objectForKey:@"ExcerciseList"]; //from plist
NSString *item = [list objectAtIndex:indexPath.row-1];
UITableViewCell *thisCell = [tableView cellForRowAtIndexPath:indexPath];
if (thisCell.accessoryType == UITableViewCellAccessoryNone)
{
thisCell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
thisCell.accessoryType = UITableViewCellAccessoryNone;
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:item message:nil delegate:nil cancelButtonTitle:@"ok" otherButtonTitles: nil] ;
[alert show];
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
#pragma mark- Table View DataSource and Delegates
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (self.isOpen&&self.selectIndex.section == indexPath.section&&indexPath.row!=0) {
static NSString *CellIdentifier = @"Cell1";
_cell = (Cell1*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!_cell) {
_cell = [[[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil] objectAtIndex:0];
//[[[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil] objectAtIndex:0];
}
NSArray *list = [[dataList objectAtIndex:self.selectIndex.section] objectForKey:@"ExcerciseList"];
_cell.titleLabel.text = [list objectAtIndex:indexPath.row-1];
//[_cell changecheckboxWithUp:([self.selectIndex isEqual:indexPath]?YES:NO)];
return _cell;
}
else
{
static NSString *CellIdentifier = @"view_TableView_List";
cell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell=[[CustomCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
NSString *name = [[dataList objectAtIndex:indexPath.section] objectForKey:@"Excercise_Name"];
cell.Lbl_Excercise_Name.text = name;
cell.Lbl_Excercise_Name.font=[UIFont fontWithName:@"Hustlers Rough Demo" size:40.0f];
NSString *ImageName=[[dataList objectAtIndex:indexPath.section] objectForKey:@"Excercise_Image"];
[cell.imageView_Excercise_Image setImage:[UIImage imageNamed:ImageName]];
[cell changeArrowWithUp:([self.selectIndex isEqual:indexPath]?YES:NO)];
return cell;
}
}
我的问题是如何在所选部分显示复选框?
对不起!如果格式不正确(新堆栈)!谢谢你!