簡體   English   中英

當我在集合視圖中單擊按鈕時,我無法將值傳遞給下一個視圖控制器

[英]when I click button in collection view, i I can't pass value to next view controller

我遇到一個問題。 我使用了集合視圖設置更多按鈕。 我需要單擊按鈕,並將索引值傳遞給“ NextViewController”。 但是當我單擊按鈕時。 它顯示在下面的錯誤消息中。

我嘗試找出錯誤所在。 但是我找不到。

有誰能給我一些提示嗎?

非常感謝你。

========== 錯誤消息 ===========

由於未捕獲的異常'NSInvalidArgumentException'而終止應用程序,原因:'-[UIViewController itemsArray:]:無法識別的選擇器已發送到實例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在這行中,您的按鈕操作方法名稱為: jumpToNextView

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

而是在選擇器或更改方法名稱中更改jumpToDrScheduleList:

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

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

storyboard檢查NextViewController的類名稱。 它應該是NextViewController 但是作為

我可以在崩潰日志中看到類名稱為UIViewController和UIViewController與ItemsArray完全不同。

多數民眾贊成在這里崩潰的原因。

修改這個

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

 [cell.cateBtn addTarget:self action:@selector(jumpToDrScheduleList:) forControlEvents:UIControlEventTouchUpInside];

UIControlEventTouchUpInside的按鈕和事件的選擇器;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM