ios - 当我在 Collection View 中单击按钮时,我无法将值传递给下一个 View Controller

标签 ios objective-c cocoa-touch collectionview

我遇到了一个问题。我使用了 Collection View 设置更多按钮。我需要单击按钮并将索引值传递给“NextViewController”。但是当我点击按钮时。下面显示错误消息。

我尝试找出错误所在。但我找不到。

有人可以给我一些提示吗?

非常感谢。

==========错误消息 ===========

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '- [UIViewController itemsArray:]: unrecognized selector sent to instance 0x9e78220'

======================================

========== ListViewController.m==========

@interface ListViewController ()
{
    NSMutableArray * itemsArray ;

}
end
...
...  //itemsArray had some data from webesrvice
...
-(UICollectionViewCell*) collectionView:(UICollectionView *)collectionView     cellForItemAtIndexPath:(NSIndexPath *)indexPath
{

CustomizedCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CustomizedCell" forIndexPath:indexPath];
 NSInteger targetIndex = indexPath.row + indexPath.section*3;

if( targetIndex < itemsArray.count )
{

        [cell.cateBtn setTitle:[[itemsArray objectAtIndex:targetIndex] itemName] forState:UIControlStateNormal];

            cell.cateBtn.tag = targetIndex;
            [cell.cateBtn addTarget:self action:@selector(jumpToNextView:) forControlEvents:UIControlEventAllEvents];
            return cell;
}

-(void)jumpToNextView:(UIButton*)sender
{

    [self performSegueWithIdentifier:@"MySegueName" sender:sender];
}
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{


    NextViewController *nextViewController =        
          segue.destinationViewController;
       nextViewController. itemsArray = itemsArray;
}

-(BOOL) shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
{


    if( targetIndex < itemsArray.count )
         return YES;
     else
         return NO;
}

========== NextViewController.h =========

@interface NextViewController : UIViewController

@property (strong, nonatomic) NSMutableArray *itemsArray;
@end

最佳答案

我猜问题出在您的按钮操作方法名称:jumpToNextView 在这一行中:

        [cell.cateBtn addTarget:self action:@selector(jumpToNextView:) forControlEvents:UIControlEventAllEvents];

而是更改选择器中的jumpToDrScheduleList:或更改方法名称。

-(void)jumpToNextView:(UIButton*)sender
{

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

关于ios - 当我在 Collection View 中单击按钮时,我无法将值传递给下一个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21824880/

相关文章:

objective-c - 如何在 iphone 中以 jpg 或 png 格式保存图像?

iphone - 何时捕获 UILabel 的高度?

objective-c - 从 NSMutableDictionary 中删除对象时出现 EXC_BAD_ACCESS 错误

iphone - 如果按下 subview 的按钮如何取消 UIGestureRecognizer

ios - 是否可以在 iOS 5.1.1 iPad 设备中运行使用 5.0 SDK 部署的 iPhone 应用程序

ios - 在每行 uicollectionview 中适合给定数量的单元格

ios - iOS-将 “objects”添加到现有应用中(越狱)

objective-c - 如何设置 NSSegmentedControl 背景图像?

iphone - CMMotionManager 不产生任何 .deviceMotions

iphone - 使用 ShareKit 将图像发布到 Facebook