I have a custom viewForHeaderInSection
on a UITableView
- let's call it HeaderCell
(a simple subclass of UITableViewCell
) that has the weirdest behaviour:
When I click on the section header:
tableView:didSelectRowAtIndexPath:
with the indexPath
of the first UITableViewCell
of that section. Like I was clicking on the cell, but no. I'm clicking on the header.The thing is, if I replace that custom HeaderCell
onviewForHeaderInSection
with a simple UIView
, that doesn't happen anymore! I've checked for any actions linked on that xib and its class, couldn't find any addTarget:
or any xib action.
Other weird factor: it does not happen on the first HeaderCell (section 0) only happens on section >= 1.
On HeaderCell
class, i just need to implement:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
return;
}
This a last resort solution. Anyone has detected this behaviour before?
You shouldn't be using subclasses of UITableViewCell
for headers/footers. Use UITableViewHeaderFooterView
(if you can live with >= iOS6) or simply UIView
otherwise.
use return cell.contentView
instead of return cell
if you are using UITableViewCell
for header/footer
You can do it through setEnableUserInteraction method. Pls refer the code given,
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
[cell setUserInteractionEnabled:YES];
if([indexPath row] == 0)
[cell setUserInteractionEnabled:NO];
return cell;
}
Hope this will help you :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With