Can i hide my button inside cell when edit mode? My cell populate by array, save in plist. This is my code
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [titleArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"the indexpath.row = %i",indexPath.row);
UITableViewCell *cell = [[UITableViewCell alloc]init];
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setFrame:CGRectMake(250.0, 25.0, 30.0, 30.0)];
[button setTitle:@"!" forState:UIControlStateNormal];
[button setTitle:@"X" forState:UIControlStateSelected];
[button setTag:indexPath.row + 100];
[button addTarget:self action:@selector(onoffBtn:) forControlEvents:UIControlEventTouchUpInside];
// my label code
UIImageView *bgCell = [[UIImageView alloc]initWithFrame:CGRectMake(0,0 , 320, 80)];
bgCell.image = [UIImage imageNamed:@"BG.jpeg"];
[cell.contentView addSubview:button];
// other cell contentView addSubview everything
return cell;
[tableView reloadData];
}
This is my edit button
- (IBAction)editBtn:(id)sender
{
UIButton *editBtn = (UIButton *)sender;
editBtn.selected = !editBtn.selected;
if (editBtn.selected)
{
button.hidden = YES;
[self.tableView setEditing:YES animated:YES];
}
else
{
button.hidden = NO;
[self.tableView setEditing:NO animated:YES];
}
}
with above code, my button hide in last cell only, just say if i have 3 cells. How do i hide all button hide when in edit mode? i want all button is hiding. Below is my onoffBtn.
- (IBAction)onoffBtn:(id)sender
{
tempIndexPath = [_tableView indexPathForCell:(UITableViewCell*)[[sender superview] superview]];
UITableViewCell *cell = [_tableView cellForRowAtIndexPath:tempIndexPath];
UIButton *onoffBtn = (UIButton *)[cell.contentView viewWithTag:tempIndexPath.row+100];
onoffBtn.selected = !onoffBtn.selected;
if (onoffBtn.selected)
{
// start
}
else
{
// stop
}
}
Please teach me more. Thank you.
You will have to call this method for all the UiTableViewCells of the table: