故事板上的自定义单元格有问题.我需要从被调用的方法访问标签
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
我如何在我的代码中定义它?当我使用IBOutlet然后它可能导致错误.
那我该如何访问标签呢
cell.textlable.text ??

非常感谢.
我有一个tableViewController,单元格包含一个按钮和一个标签.Person当用户点击按钮时,我需要获取单元格的文本(实际上是单元格的对象).
当用户点击按钮时,执行以下方法;
-(void) buttonOfCellClicked{
// here i need to access the `Person` object that the user clicked
}
Run Code Online (Sandbox Code Playgroud)
我该如何编写这段代码?
编辑:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
Run Code Online (Sandbox Code Playgroud)
Person*person = [personsArr objectAtIndex:indexPath.row];
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] ;
label = [[UILabel alloc]initWithFrame:CGRectMake(15, 5, 75, 60)];
label.text =person.firstName;
[cell addSubview:label];
UIButton *button= [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(buttonOfCellClicked) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:button];
}
Run Code Online (Sandbox Code Playgroud) 我有子类化UITableViewCell。在这里,我为按钮制作了一个插座。单击该按钮后,它应在其他ViewController中执行一个功能。我已经试过了:
override func awakeFromNib() {
super.awakeFromNib()
reloadTableView.addTarget(self, action: #selector(multiplayerChannelView.tappedOnReloadTableView), for: .touchUpInside)
}
Run Code Online (Sandbox Code Playgroud)
但是,由于以下错误而崩溃:
[test.CreateChannelCell tappedOnReloadTableView]:无法识别的选择器发送到实例0x7fc1198b5200
该功能存在,没有错字。为什么这不起作用?这个问题看起来一样,只是它不是在swift 3.0中编写的。如何在UITableViewCell中为UIButton设置操作
multiplayerChannelView是保存UITableView的视图控制器。我得到了带有UITableViewCell子类化的单独的.swift文件。