我遇到了一个问题。我使用了 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/