iOS 自定义Cell里面定义了个UIButton,怎么才能点击UIButton跳转页面

2025-02-24 16:36:52
推荐回答(1个)
回答1:

在cell.h声明一个protocol.
@proDelegate
-(v)someProMethod:(integer)cellRow;
@end
且声明属性
@property(xx,xx) id customDelegate.
@property(xx,xx) interger cellRow;
button点击事件方法里
-(v)btnClicked:(id)sender
{
if(_customDelegate != nil && [_customDelegate responseToSelector:@selector(someProMethod:)])

{
[_customDelegate someProMethod:cellRow];

}
}

在加载tableview的viewController someVC中,
someVC.h
#import "xxxCell.h"

@class SomeVC:ViewController

@implementation
-(cell *)cellForRow....
{
cell = ...

cell.dataSource = self;
cell.delegate = self;

//因为已经有delegate了,所以你定义的委托取其他名称,如customDelegate
cell.customDelegate = self;
cell.cellRow = indexPath.row;

}

//实现委托方法
-(v)someProMethod:cellRow
{
//跳转页面。需要可以在这个方法里传cell.row参数。

if(cellRow = 7)

{
//点击了第7行的按钮

}

}

@end