【问题标题】:Sending a info to detailview from UICollectionView is not working?从 UICollectionView 向 detailview 发送信息不起作用?
【发布时间】:2014-03-07 18:51:35
【问题描述】:

我想我没有在标题中解释清楚,问题就在这里,我有一个从 json 提供的集合视图,但是当我查看详细信息时它崩溃了,我认为问题出在这部分代码中当我将信息发送到详细信息时:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

    if ([[segue identifier]isEqualToString:@"detailView"]) {


        NSIndexPath *myIndexPath = [self.collectionView indexPathsForSelectedItems];
        int row = [myIndexPath row];
        MenuDetailViewController *menu = [segue destinationViewController];
        EntryJson *entry = [[InfoWeb sharedInstance] entryAtIndex:row];
        menu.galeriademo = entry.imagenes;
        menu.DetailModalprim = @[entry.title == nil ? @"" : entry.title,
                                 entry.date == nil ? @"" : entry.date,
                                 entry.desc == nil ? @"" : entry.desc,
                                 entry.mainimage == nil ? @"" : entry.mainimage,
                                 entry.seccion == nil ? @"" : entry.seccion];


    }

}

在 tableview 中,IndexPath 类似于: NSIndexPath *myIndexPath = [self.collectionView indexpathforselectedRow];

我有一个像这样工作的表格视图,它很好,但是当我更改为集合视图时,我遇到了这个问题。崩溃日志是下一个:

2014-03-07 12:41:00.696 CMT[28640:70b] -[__NSArrayI row]: unrecognized selector sent to instance 0xc34d180
2014-03-07 12:41:00.698 CMT[28640:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI row]: unrecognized selector sent to instance 0xc34d180'

所以我需要你的帮助!谢谢!

【问题讨论】:

    标签: ios objective-c uicollectionview


    【解决方案1】:

    indexPathsForSelectedItems 返回一个 NSarray,而不是 NSIndexPath

    NSIndexPath *myIndexPath = [self.collectionView indexPathsForSelectedItems];
    

    应该是

    NSArray *myIndexPaths = [self.collectionView indexPathsForSelectedItems];
    NSIndexPath *myIndexPath = [myIndexPahts objectAtIndex:0];
    

    【讨论】:

    • 当然,谢谢,我是初学者,希望你能理解我:)
    猜你喜欢
    • 2017-01-11
    • 1970-01-01
    • 2018-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-01
    相关资源
    最近更新 更多