ios - 如何将变量设置为所选单元格的 indexPath.section?

标签 ios objective-c uitableview

<分区>

当用户点击我的 UITableView 中的单元格时,我想将 sectionSelected 变量设置为该单元格的 indexPath.section相应的部分,然后将该变量发送到 segue 中的下一个 View Controller 。

这是我目前正在尝试的方式:

MatchCenterViewController.h:

@property (assign, nonatomic) NSInteger *sectionSelected;

MatchCenterViewController.m:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //Set _sectionSelected variable to the section index
    self.sectionSelected = indexPath.section;

[self performSegueWithIdentifier:@"MCExpandedSegue" sender:self];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"MCExpandedSegue"]){
        MCExpandedViewController *controller = (MCExpandedViewController *) segue.destinationViewController;
        controller.sectionSelected = self.sectionSelected;
    }
}

这是行不通的,看来这是因为我在行设置 self.sectionSelected 上收到以下警告: 从“NSInteger”(又名“long”)分配给“NSInteger *”(又名“long *”)的指针转换不兼容

如何正确设置变量?

最佳答案

改变

@property (assign, nonatomic) NSInteger *sectionSelected;

@property (assign, nonatomic) NSInteger sectionSelected;

关于ios - 如何将变量设置为所选单元格的 indexPath.section?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35023196/

上一篇:ios - NSURLSession 完成处理程序非常慢

下一篇:ios - 在默认 uitabbar 中为选定和取消选定的统计信息设置彩色图像

相关文章:

ios - 每个测试版更新都需要通过 Apple TestFlight 批准吗?

ios - Xcode 中具有用户定义设置的程序中出现意外的 '@'

ios - 无法将参数传递给 UITableViewCell

ios - RestKit 发布嵌套托管对象会创建重复项

ios - 滚动时以曲线/圆弧路径移动 View

objective-c - 是否可以以编程方式访问与我的 cocoa 绑定(bind)关联的 NSValueTransformer ?

ios - CollectionView 中单元格之间的间距

ios - 按下 tableView 单元格时在不同的 ViewController 中打开 URL

ios - selectRowAtIndexPath 在 vi​​ewWillAppear 中失败

iphone - 在 .m 文件中声明 Objective C 接口(interface)的实例变量(在 Release模式下)