So I have a UITableView here with several sections and with several rows per section. Both the number of sections and the number of rows per section is different from each specific case the tableview is used for.
I have two UIButtons in the tableview that both fire their separate methods.
The problem is that I'm having trouble figuring out which section and which row the button belongs to in the method that gets fired when you push the button. After some thinking I realized I could set the row as the tag of the button (since this gets passed into the method I'm running), but that leaves the section undetermined. I then thought perhaps I could set the title of the button to the section, since I'm using an image on the button, but for some reason I can't seem to extract this in the method that gets fired.
Buttons:
The increaseLine method looks like this:
The sender here comes out as:
With no mention of the title. Trying to run that second line that is commented out the app crashes and there's a warning in XCode that I'm passing argument 1 from an incompatible pointer type.
Help!
I have two UIButtons in the tableview that both fire their separate methods.
The problem is that I'm having trouble figuring out which section and which row the button belongs to in the method that gets fired when you push the button. After some thinking I realized I could set the row as the tag of the button (since this gets passed into the method I'm running), but that leaves the section undetermined. I then thought perhaps I could set the title of the button to the section, since I'm using an image on the button, but for some reason I can't seem to extract this in the method that gets fired.
Buttons:
Code:
UIButton *increaseButton = [UIButton buttonWithType:UIButtonTypeCustom];
NSString *section = [NSString stringWithFormat:@"Section: %i",(indexPath.section - 2)];
int line = ((indexPath.row - 1) / 2);
[increaseButton setTag:line];
[increaseButton setTitle:section
forState:UIControlStateNormal];
[increaseButton setTitleColor:[UIColor greenColor]
forState:UIControlStateNormal];
[increaseButton setImage:[UIImage imageNamed:@"bidincrease.png"]
forState:UIControlStateNormal];
[increaseButton setFrame:CGRectMake(10, 10, 30, 25)];
[increaseButton setUserInteractionEnabled:YES];
[increaseButton addTarget:self
action:@selector(increaseLine:)
forControlEvents:UIControlEventTouchUpInside];
[cell setAccessoryView:increaseButton];
UIButton *decreaseButton = [UIButton buttonWithType:UIButtonTypeCustom];
[decreaseButton setTag:line];
[decreaseButton setTitle:section
forState:UIControlStateNormal];
[decreaseButton setImage:[UIImage imageNamed:@"biddecrease.png"]
forState:UIControlStateNormal];
[decreaseButton setFrame:CGRectMake(10, 10, 30, 25)];
[decreaseButton setUserInteractionEnabled:YES];
[decreaseButton addTarget:self
action:@selector(decreaseLine:)
forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:decreaseButton];
The increaseLine method looks like this:
Code:
- (void)increaseLine:(UIButton *)sender
{
NSLog(@"Increasing line %@",sender);
// NSLog("Section: %@\nLine: %i",[sender currentTitle],[sender tag]);
}
The sender here comes out as:
Increasing line <UIButton: 0x3973d60; frame = (271 10; 30 25); opaque = NO; tag = 2; layer = <CALayer: 0x3999710>>
With no mention of the title. Trying to run that second line that is commented out the app crashes and there's a warning in XCode that I'm passing argument 1 from an incompatible pointer type.
Help!