1.cell.accessoryView = [self createAccessoryView];
2.- (UIButton *)createAccessoryView{
UIButton *accessoryButton = [UIButton buttonWithImageName:@"ic_sub_department.png"];
[accessoryButton addTarget:self action:@selector(accessoryButtonTapped:withEvent:) forControlEvents:UIControlEventTouchUpInside];
return accessoryButton;
}
- (void)accessoryButtonTapped:(UIButton *)button withEvent:(UIEvent *)event{
// 确定点击位置
NSIndexPath *indexPath = [_tableView.tableView indexPathForRowAtPoint:[[[event touchesForView:button] anyObject] locationInView:_tableView.tableView]];
if (indexPath == nil)
return;
[_tableView.tableView.delegate tableView:_tableView.tableView accessoryButtonTappedForRowWithIndexPath:indexPath];
}
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{
SyOrganization *theOrg = (SyOrganization *)[_dataArray objectAtIndex:indexPath.row];
[_departmentIDArray addObject:[NSNumber numberWithLongLong:theOrg.ID]];
[self requestDeparmentListAccountID:_selectedAccountID parentID:theOrg.ID isAccount:NO];
if (_delegate && [_delegate respondsToSelector:@selector(addUpperLevelButtonOnTitleBarWithTarget:)]) {
[_delegate addUpperLevelButtonOnTitleBarWithTarget:self];
}
}