如何将 IBAction 事件赋予自定义单元格的 UIButton?
我想提供自定义单元格的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嘿,在
Customcell
类中有一个IBOutlet
按钮,然后在hey have an
IBOutlet
of you button inCustomcell
class then in