简体   繁体   English

当我在集合视图中单击按钮时,我无法将值传递给下一个视图控制器

[英]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.

相关问题 单击下一个视图控制器的按钮时,如何显示加载标签? - How can I get my loading label to show up when I click button to next view controller? Swift / XCode-为什么在按下tableViewCell时不能将数据传递给下一个视图控制器? - Swift/XCode - Why can't I pass data to the next view controller when a tableViewCell is pressed? 以编程方式加载后,如何将数据传递给下一个视图控制器? - How can I pass data to the next view controller when it is loaded programmatically? 单击另一个视图控制器中的按钮时实现原型单元 - implement prototype cell when I click a button in another view Controller 当我单击IOS中的按钮时,为什么视图不显示? - Why the view doesn't show when I click the button in IOS? 如何以编程方式将下一个视图控制器推入导航控制器? - How can I push the next view controller on a navigation controller programmatically? 当我在收藏夹视图中单击一个项目时,出现此错误 - When i click an item in my collection view i got this error 如何在一个View Controller中拥有多个Collection View? - How can I have multiple Collection Views in one View Controller? 启动应用程序时未出现下一个视图控制器 - next view controller is not appearing when i launched apps 当我打电话给下一个视图控制器时出错 - error when i am calling next view controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM