iphone - UIButton 放置在 tableviewcell 顶部

标签 iphone objective-c uitableview uibutton

我有 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/

相关文章:

ios - Xcode 7 - 宏名称必须是标识符

ios - 在模型层过滤 NSFetchedResultsController

ios - 如何将 Objective-c 中的数据类型匹配到 Swift 协议(protocol)?

ios - 为什么 tableview 在 iOS 6+ 模拟器上工作正常,但在 iOS 5 模拟器上它崩溃了

ios - 使用 NSUserDefaults (Swift) 在 ViewController 和 TableVC 之间传递数据

iphone - 有了 obj-c 中的属性,我们需要声明实例变量吗?

iphone - 单击电子邮件中的音频链接后,如何打开我的应用程序音频播放器来播放音频?

iphone - 如何编辑文本字段中的标签?

iphone - 如何在 CFStream 中启用更多握手密码?

ios - 制作tableview样式时遇到麻烦