我有UIButton它被放置在每个UITableviewCell的顶部。它是自定义表视图。当我点击tableviewcell时它会进入另一个tableview其中(tableview)包含每个单元格中的数据。
这是我获得第二个tableview ....的详细信息的方式customCellData是给出小区号的数据库查询方法。(例如,如果我点击第一个tableview的第二个单元格customcell返回值)(bookArray -包含第一个tableviewcell的第二个单元格中存在的项目列表)
以下代码是didSelectForRowAtIndexPath
NSDictionary *selectedAuthor = nil;
NSArray *sectionArray=[mainIndexDictionary objectForKey:[allKeysArray objectAtIndex:indexPath.section]];
selectedAuthor = [sectionArray objectAtIndex:indexPath.row];
iPath=[[selectedAuthor objectForKey:@"SymptIndexID"] intValue];
NSLog(@"iPath - %d",iPath);
authortitleString=[[selectedAuthor objectForKey:@"authorIndexName"]stringByAppendingString:@" cure!"];
}
bookArray=[objDB customCellData:(NSInteger)iPath];
[self.view bringSubviewToFront:authorView];
[bookTableView scrollRectToVisible:CGRectMake(0.0, 0.0, 320.0,10.0) animated:NO];
[bookTableView reloadData]
现在我想编程在这样一种方式,当我点击UIButton这是在第一个表视图它应该包含第二个表视图的数据。我不能访问indexPath,因为我将在单独的方法中这样做(在didselectrowatindexpath中,如果我为特定的单元格提供indexPath,则可以找到indexPath)
谁来帮帮我。
更新代码
in cellForRowAtIndexPath
cell.shareFacebookButton.tag = indexPath.row;
[cell.shareFacebookButton addTarget:self action:@selector(facebookShare:) forControlEvents:UIControlEventTouchUpInside];
return cell;
-(IBAction)facebookShare:(id)sender
{
UIButton *button = (UIButton *)sender;
UITableViewCell *cell = (UITableViewCell *)button.superview.superview;
UITableView *tableView = (UITableView *)cell.superview;
NSIndexPath *indexPath = [tableView indexPathForCell:cell];
NSInteger indexPathNumber = indexPath.row;
NSLog(@"IndexPath is -- > %d" , indexPathNumber);
}
回答更新
好的,下面是你需要用于自定义单元格按钮的函数
"cellForRowAtIndexPath"或使用任何其他给定的适当函数。
要确定点击了哪个按钮,执行如下操作
<buttonid>.tag = <indexPath>.row;
问候,拉维