如何将 IBAction 事件赋予自定义单元格的 UIButton?

发布于 2025-01-02 23:29:17 字数 2193 浏览 0 评论 0原文

我想提供自定义单元格的 UIButton IBAction 事件。

我尝试使用下面的代码,但它崩溃了。

我怎样才能创建委托&在我的 UITableView 类中使用它吗?

Customcell 类

-(IBAction)btnShowAttachmentClick:(UITableView *)aTblViewCommon
{
    [(ShowTechAndProfDetailsVC *)aTblViewCommon.delegate performSelector:@selector(showAttachmentsFromCell:) withObject:nil];
}

具有 UITableView 的 UIViewController 类

-(void)showAttachmentsFromCell:(UIButton *)sender
{
    gotoClass *obj = [[gotoClass alloc] initWithNibName:@"gotoClass" bundle:nil];
    [self.navigationController pushViewController:obj animated:YES];
    [obj release];
}

这里是 cellForRowAtIndexPath

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{  
    if(appDelegate.intCountSwipeForView == 1 || appDelegate.intCountSwipeForView == 2)
    {
        objCellView = [ViewExpAndEduCustomCell dequeOrCreateInTable:tableView];

        objCellView.selectionStyle = UITableViewCellSelectionStyleNone;
        //objCellView.btnPaperClip.tag = indexPath.row;
        [objCellView.btnPaperClip addTarget:self action:@selector(showAttachmentsFromCell:) forControlEvents:UIControlEventTouchUpInside];


        objCellView.lblName.text = @"asdfsdf";
        objCellView.lblTitleOrCourse.text = @"asdf";
        objCellView.lblStartDate.text = @"23-Nov-2001";
        objCellView.lblEndDate.text = @"04-Feb-2002";


        [objCellView.txtViewSummary setTextColor:TEXT_COLOR_GRAY_FOR_TABLECELL];
        [objCellView.txtViewSummary setFont:[UIFont systemFontOfSize:17.0]];
        [objCellView.txtViewSummary setContentInset:UIEdgeInsetsMake(-5, 0, 0, 0)];
        [objCellView.txtViewSummary setBackgroundColor:[UIColor clearColor]];
        [objCellView.txtViewSummary setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
    }
if(appDelegate.intCountSwipeForView == 1){
        objCellView.txtViewSummary.text = @"Experience.This is sample text.This text can be of 150 characters.No more than that.You can also attach your achievment but only pdf,Image or video";
        return objCellView;
}

I want to give custom cell's UIButton IBAction event.

I tried with below code but it crashes.

How can I create delegate & use that in my UITableView class?

Customcell class

-(IBAction)btnShowAttachmentClick:(UITableView *)aTblViewCommon
{
    [(ShowTechAndProfDetailsVC *)aTblViewCommon.delegate performSelector:@selector(showAttachmentsFromCell:) withObject:nil];
}

UIViewController class having UITableView

-(void)showAttachmentsFromCell:(UIButton *)sender
{
    gotoClass *obj = [[gotoClass alloc] initWithNibName:@"gotoClass" bundle:nil];
    [self.navigationController pushViewController:obj animated:YES];
    [obj release];
}

Here is cellForRowAtIndexPath

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{  
    if(appDelegate.intCountSwipeForView == 1 || appDelegate.intCountSwipeForView == 2)
    {
        objCellView = [ViewExpAndEduCustomCell dequeOrCreateInTable:tableView];

        objCellView.selectionStyle = UITableViewCellSelectionStyleNone;
        //objCellView.btnPaperClip.tag = indexPath.row;
        [objCellView.btnPaperClip addTarget:self action:@selector(showAttachmentsFromCell:) forControlEvents:UIControlEventTouchUpInside];


        objCellView.lblName.text = @"asdfsdf";
        objCellView.lblTitleOrCourse.text = @"asdf";
        objCellView.lblStartDate.text = @"23-Nov-2001";
        objCellView.lblEndDate.text = @"04-Feb-2002";


        [objCellView.txtViewSummary setTextColor:TEXT_COLOR_GRAY_FOR_TABLECELL];
        [objCellView.txtViewSummary setFont:[UIFont systemFontOfSize:17.0]];
        [objCellView.txtViewSummary setContentInset:UIEdgeInsetsMake(-5, 0, 0, 0)];
        [objCellView.txtViewSummary setBackgroundColor:[UIColor clearColor]];
        [objCellView.txtViewSummary setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
    }
if(appDelegate.intCountSwipeForView == 1){
        objCellView.txtViewSummary.text = @"Experience.This is sample text.This text can be of 150 characters.No more than that.You can also attach your achievment but only pdf,Image or video";
        return objCellView;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜点 2025-01-09 23:29:17

嘿,在 Customcell 类中有一个 IBOutlet 按钮,然后在

- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    //creating cell or resusing cell

    //after getting the cell and casting it into your Customcell
        [cell.mButton addTarget:self action:@selector(showAttachmentsFromCell:) forControlEvents:UIControlEventTouchUpInside];

}

hey have an IBOutlet of you button in Customcell class then in

- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    //creating cell or resusing cell

    //after getting the cell and casting it into your Customcell
        [cell.mButton addTarget:self action:@selector(showAttachmentsFromCell:) forControlEvents:UIControlEventTouchUpInside];

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文