In my app i have to implement checkbox functionality in tableview cell.By clicking on that checkbox another label will be created in the same cell.1st how to implement checkbox functionality?i have created custom cell. here is my code which i tried but it doesnt work.
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
UIButton *btnUncheck=[[UIButton alloc] initWithFrame:CGRectMake(260, 35, 20, 20)];
btnUncheck=[UIButton buttonWithType:UIButtonTypeCustom];
btnUncheck.tag=indexPath.row;
// [btnUncheck setImage:[UIImage imageNamed:@"NO.png"] forState:UIControlStateNormal];
[btnUncheck addTarget:self action:@selector(checkBoxClicked:) forControlEvents:UIControlEventTouchUpInside];
[view addSubview:btnUncheck]
-(void)checkBoxClicked:(id)sender{
if(favoriteChecked==NO)
{
[sender setImage:[UIImage imageNamed:@"YES.png"] forState:UIControlStateNormal];
favoriteChecked=YES;
}
else
{
[sender setImage:[UIImage imageNamed:@"NO.png"] forState:UIControlStateNormal];
favoriteChecked=NO;
}
}
Cast your sender from id type to button type using
UIButton *btn = (UIButton *)sender;and then change image forbtn.Also change
[view addSubview:btnUncheck]to[cell.contentView addSubview:btnUncheck];And for doing that you will require to create a TableViewcellHope this helps.