iphone – 附件动作segue(UITableViewController)
发布时间:2020-12-15 01:58:04 所属栏目:百科 来源:网络整理
导读:我试图通过IB做segue,当在tableView中按下单元格附件时切换视图。 我的IB图片: 1.我从tableviewcontroller的单元格拖动到另一个视图,然后选择Accessory Action – 推 当我运行我的项目我得到错误: [ setValue:forUndefinedKey:]: this class is not key
我试图通过IB做segue,当在tableView中按下单元格附件时切换视图。
我的IB图片: 1.我从tableviewcontroller的单元格拖动到另一个视图,然后选择Accessory Action – >推 当我运行我的项目我得到错误:
我认为这可能是重复使用单元格标识符错误。 我的cellForRowAtIndexPath:方法: static NSString *CellIdentifier = @"champion cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; NSString *cellIconName = ((championList *)[self.champions objectAtIndex:indexPath.row]).championImage; UIImage *cellIcon = [UIImage imageNamed:cellIconName]; [[cell imageView] setImage:cellIcon]; cell.imageView.frame = CGRectMake(0.0f,0.0f,70.0f,70.0f); cell.imageView.layer.cornerRadius = 7; [cell.imageView.layer setMasksToBounds:YES]; cell.textLabel.text = ((championList *) [self.champions objectAtIndex:indexPath.row]).championName; cell.detailTextLabel.text = ((championList *) [self.champions objectAtIndex:indexPath.row]).championId; return cell; 我可以使用performSegueWithIdentifier:方法来解决这个问题,但是我想知道为什么我在IB中遇到了附件动作问题。 解决方法
当我将ctrl从原型单元格的细节附件按钮拖到下一个视图控制器时,我遇到了这个问题。所以相反,我从表视图控制器本身做了拖动,并添加了一些代码。
Objective-C的: - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { [self performSegueWithIdentifier: @"EditUser" sender: [tableView cellForRowAtIndexPath: indexPath]]; } Swift 3.0: func tableView(_ tableView: UITableView,accessoryButtonTappedForRowWith indexPath: IndexPath) { performSegue(withIdentifier: "EditUser",sender: tableView.cellForRow(at: indexPath)) } 这适用于iOS 5.0 – 10.x (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |