[英]when I click button in collection view, i I can't pass value to next view controller
I had encounter a question. 我遇到一个问题。 I used collection view set more button. 我使用了集合视图设置更多按钮。 I need click button and passs index value to "NextViewController". 我需要单击按钮,并将索引值传递给“ NextViewController”。 But when I click the button. 但是当我单击按钮时。 It is show below error message. 它显示在下面的错误消息中。
I try to find where's error. 我尝试找出错误所在。 But I can't find. 但是我找不到。
Have any one can give me some hint? 有谁能给我一些提示吗?
thank you very much. 非常感谢你。
========== error message =========== ========== 错误消息 ===========
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '- [UIViewController itemsArray:]: unrecognized selector sent to instance 0x9e78220' 由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[UIViewController itemsArray:]:无法识别的选择器已发送到实例0x9e78220'
=================================== ===================================
=========== ListViewController.m ========== =========== 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 ========= ========== NextViewController.h =========
@interface NextViewController : UIViewController
@property (strong, nonatomic) NSMutableArray *itemsArray;
@end
I guess the Problem is with your button Action method name: jumpToNextView
in this line: 我猜问题jumpToNextView
在这行中,您的按钮操作方法名称为: jumpToNextView
:
[cell.cateBtn addTarget:self action:@selector(jumpToNextView:) forControlEvents:UIControlEventAllEvents];
Rather Change jumpToDrScheduleList:
in selector or Change Method name. 而是在选择器或更改方法名称中更改jumpToDrScheduleList:
-(void)jumpToNextView:(UIButton*)sender
{
[self performSegueWithIdentifier:@"MySegueName" sender:sender];
}
check the class name for NextViewController
in storyboard
. 在storyboard
检查NextViewController
的类名称。 it should be NextViewController
. 它应该是NextViewController
。 but as 但是作为
i can see in crash log class name is UIViewController & UIViewController has nothing like itemsArray. 我可以在崩溃日志中看到类名称为UIViewController和UIViewController与ItemsArray完全不同。
thats the reason you are getting crash here. 多数民众赞成在这里崩溃的原因。
modify this 修改这个
[cell.cateBtn addTarget:self action:@selector(jumpToNextView:) forControlEvents:UIControlEventAllEvents];
with 同
[cell.cateBtn addTarget:self action:@selector(jumpToDrScheduleList:) forControlEvents:UIControlEventTouchUpInside];
selector for button & event to UIControlEventTouchUpInside; UIControlEventTouchUpInside的按钮和事件的选择器;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.