I have a UITableView and inside each header, I have a gesture recognizer. Inside the gesture handler, I want to make changes to something inside the headerview.
-(void) sectionHeaderButtonPressed: (UIButton *)sender{
NSLog(@"Header Button pressed");
//UIView *mySubView = [sender.view.subviews objectAtIndex:0];
NSLog(@"Class: %@",[self class]);
int count = [self.view.subviews count];
NSLog(@"Self.view.subviews: %u",count);
Class buttonClass = NSClassFromString(@"UIButton");
for (int i=0; i < count; i++){
int subViewCount = [[self.view.subviews objectAtIndex:i] subviews].count;
Class className = [[self.view.subviews objectAtIndex:i] class];
NSLog(@"SubView (%u) Class:%@ SubViews: %u",i,className,subViewCount);
for (int j=0; j < subViewCount; j++){
Class className01 = [[[self.view.subviews objectAtIndex:i].subviews objectAtIndex:j ] class];
NSLog(@"----SubSubView (%u) Class:%@",j,[[[self.view.subviews objectAtIndex:i].subviews objectAtIndex:j ] class]);
NSLog(@"Comparing Class: %@ to Class: %@",className01, buttonClass);
if (className01 == buttonClass){
[[[self.view.subviews objectAtIndex:i].subviews objectAtIndex:j ] setTitle:@"ABCDE" forState:UIControlStateNormal];
NSLog(@"found button class");
}
}
}
}
The above code is the gesture handler and I can find the button and every other subview, but this is a real hassle.
I seem to be confused about how one object can call another object. I wanted to pass the headerview down to the gesture handler but can't figure out how to do that.
How can I directly send or access the headerview and/or it's subviews. Looking at the class name won't do much good if I have several of the same class type.
The question is about the proper way to invoke an action in another object. Running thru all the subviews doesn't seem to be the proper way. Basing the id on the class name is an error prone way to go as you might have many of the same class.
I want to have a "slide in from the side" selection menu and have that modify the header based on what the user selects from the menu. They'll tap on the header, that'll call the gesture handler, that'll call the slide out menu, the slide out menu will call the header to make it change it's contents.
It's the last part that's confusing, how do I get the menu to change the header view contents when they're completely different objects.