我有 UIButton ,它放置在每个 UITableviewCell 的顶部。这是自定义的表格 View 。当我单击 tableviewcell 时,它会进入另一个 tableview,其中(Tableview)包含每个单元格中的数据。
这是我获取第二个表格 View 详细信息的方式..customCellData是给出单元格编号的数据库查询方法..(例如,如果我单击第一个 TableView 自定义单元格的第二个单元格返回值) (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]
现在我想以这样的方式进行编程。当我单击第一个 TableView 中的 UIButton 时,它应该包含第二个 TableView 的数据。我无法访问indexPath,因为我将在单独的方法中执行此操作(在didselectrowatindexpath中,如果我为该特定单元格提供索引路径,则找到索引路径)
有人可以帮帮我吗?
更新代码
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;
问候, 拉维
关于iphone - UIButton 放置在 tableviewcell 顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15859749/