我有一个tableview,其中包含可变数量的单元格,表示与其特定教师相对应的学生.它们是具有按钮的自定义单元格,该按钮触发新VC的segue,提供有关其单元格的学生的详细信息.我的问题是:
swift中用于识别按下哪个按钮的最佳做法是什么?
一旦我知道索引路径,我就可以确定哪个学生的信息需要传递给下一个VC.在下面的帖子中,对于目标C有一个很好的答案,但我不确定如何转换为Swift.任何帮助将非常感激.
我知道这个问题有很多重复,但我的要求是我在一个单元格上添加了两个UIButtons,两个按钮都会打开两个不同的视图.如果我将属性userInteractionEnabled设置为YES,那么它将不会从下面的代码中拍摄didSelectRowAtIndexPath中的'finalID'.
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(tableView == self.tableViewProject){
static NSString *cellId = @"attachmentCellId";
attachmentCell *cell = (attachmentCell *)[self.tableViewProject dequeueReusableCellWithIdentifier:cellId];
if(!cell)
{
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"attachmentCell" owner:self options:Nil];
for(id object in nib)
{
if([object isKindOfClass:[attachmentCell class]])
{
cell = (attachmentCell *)object;
break;
}
}
UIButton *button;
button = [[UIButton alloc] initWithFrame:CGRectMake(162, 0, 75, 53)];
[button addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside];
button.userInteractionEnabled = YES;
//button.userInteractionEnabled = NO;
[cell.contentView addSubview:button];
UIButton *buttonAttach = [[UIButton alloc] initWithFrame:CGRectMake(245, 0, …Run Code Online (Sandbox Code Playgroud)