How to get index of UIButton that viewwithtag in uitableview ios
I have a problem: i want to get index of UIButton in tableview. I created
uitableview has 2 uibutton in each row, but when i click on uibutton, it
get index incorrect. Code create UITableview :
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = (UITableViewCell *)[_tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (nil == cell) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
UIButton *market = [UIButton buttonWithType:UIButtonTypeCustom];
[market setFrame:CGRectMake(200, 6, 30, 30)];
[market setTag:4000];
[market addTarget:self action:@selector(marketPressedAction:)
forControlEvents:UIControlEventTouchDown];
[cell.contentView addSubview:market];
}
UIButton *marketButton = (UIButton*)[cell.contentView viewWithTag:4000];
return cell;
}
And marketPressedAction fucntion
- (void)marketPressedAction:(id)sender
{
buttonPressed = (UIButton *)sender;
buttontag = buttonPressed.tag ;
NSLog(@"Market button click at row %d",buttontag);
}
When table has 5 row, i click on button, it show error:
-[__NSArrayM objectAtIndex:]: index 4000 beyond bounds [0 .. 4]'
Thanks in advance
No comments:
Post a Comment