0
  • I am using Xcode 6 to make the app. I have two table view controllers, Root and Second, and now I want to pass data from Second table view controller to Collection view controller. I have added a segue but there is an exception. Not sure where I have gone wrong.

SecondViewController.h

 #import <UIKit/UIKit.h>



   @interface SecondTableViewController : UITableViewController



   @property(nonatomic, strong) NSString *businessName;



   @end














   code for CollectionViewController.m



   #import "CollectionViewController.h"

   #import "CollectionViewCell.h"



   @interface CollectionViewController ()



   @end



   @implementation CollectionViewController



   NSArray * favBC;

   NSArray * relToMe;

   NSArray * repByMe;

   NSArray * redForApp;

   NSArray * appBC;



   static NSString * const reuseIdentifier = @"collectionCell";



   - (void)viewDidLoad {

       [super viewDidLoad];



       // Uncomment the following line to preserve selection between presentations

       // self.clearsSelectionOnViewWillAppear = NO;



       favBC = [NSArray arrayWithObjects:@"IDEA1",@"NEW",@"IN VAL...",@"IN ESTI...",@"READY...",@"APPROV...",@"IT

CHAN...",@"UNDER...",@"IMPLEM",@"CLOSED", nil];

       relToMe = [NSArray arrayWithObjects:@"IDEA2",@"NEW",@"IN VAL...",@"IN ESTI...",@"READY...",@"APPROV...",@"IT

CHAN...",@"UNDER...",@"IMPLEM",@"CLOSED", nil];

       repByMe = [NSArray arrayWithObjects:@"IDEA3",@"NEW",@"IN VAL...",@"IN ESTI...",@"READY...",@"APPROV...",@"IT

CHAN...",@"UNDER...",@"IMPLEM",@"CLOSED", nil];

       redForApp = [NSArray arrayWithObjects:@"IDEA4",@"NEW",@"IN VAL...",@"IN ESTI...",@"READY...",@"APPROV...",@"IT

CHAN...",@"UNDER...",@"IMPLEM",@"CLOSED", nil];

       appBC = [NSArray arrayWithObjects:@"IDEA5",@"NEW",@"IN VAL...",@"IN ESTI...",@"READY...",@"APPROV...",@"IT

CHAN...",@"UNDER...",@"IMPLEM",@"CLOSED", nil];

       // Register cell classes

       [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];



       // Do any additional setup after loading the view.

   }



   - (void)didReceiveMemoryWarning {

       [super didReceiveMemoryWarning];

       // Dispose of any resources that can be recreated.

   }



   /*

   #pragma mark - Navigation



   // In a storyboard-based application, you will often want to do a little preparation before navigation

   - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

       // Get the new view controller using [segue destinationViewController].

       // Pass the selected object to the new view controller.

   }

   */



   #pragma mark <UICollectionViewDataSource>



   - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {



       return 1;

   }





   - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {



       if([_businessName2 isEqualToString:@"IDEA1"]){

           return [favBC count];



       }else if ([_businessName2 isEqualToString:@"IDEA2"]){

           return [relToMe count];



       }else if ([_businessName2 isEqualToString:@"IDEA3"]){

           return [repByMe count];



       }else if ([_businessName2 isEqualToString:@"IDEA4"]){

           return [redForApp count];



       }else if ([_businessName2 isEqualToString:@"IDEA5"]){

           return [appBC count];

       }



       return 0;

   }



   - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

       CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier

forIndexPath:indexPath];

       if([_businessName2 isEqualToString:@"IDEA1"]){

           cell.bcRequestLabel.text = [favBC objectAtIndex:indexPath.row];



       }else if ([_businessName2 isEqualToString:@"IDEA2"]){

           cell.bcRequestLabel.text = [favBC objectAtIndex:indexPath.row];



       }else if ([_businessName2 isEqualToString:@"IDEA3"]){

           cell.bcRequestLabel.text = [favBC objectAtIndex:indexPath.row];



       }else if ([_businessName2 isEqualToString:@"IDEA4"]){

           cell.bcRequestLabel.text = [favBC objectAtIndex:indexPath.row];



       }else if ([_businessName2 isEqualToString:@"IDEA5"]){

           cell.bcRequestLabel.text = [favBC objectAtIndex:indexPath.row];

       }



       // Configure the cell



       return cell;

   }



   #pragma mark <UICollectionViewDelegate>



   /*

   // Uncomment this method to specify if the specified item should be highlighted during tracking

   - (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath {

   return YES;

   }

   */



   /*

   // Uncomment this method to specify if the specified item should be selected

   - (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {

       return YES;

   }

   */



   /*

   // Uncomment these methods to specify if an action menu should be displayed for the specified item, and react to actions performed on

the item

   - (BOOL)collectionView:(UICollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath {

   return NO;

   }



   - (BOOL)collectionView:(UICollectionView *)collectionView canPerformAction:(SEL)action forItemAtIndexPath:(NSIndexPath

*)indexPath withSender:(id)sender {

   return NO;

   }



   - (void)collectionView:(UICollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath

withSender:(id)sender {

   }

   */



   @end


   #import "SecondTableViewController.h"

   #import "CollectionViewController.h"



   @interface SecondTableViewController ()



   @end



   @implementation SecondTableViewController



   NSArray * favBC;

   NSArray * relToMe;

   NSArray * repByMe;

   NSArray * redForApp;

   NSArray * appBC;



   - (void)viewDidLoad {

       [super viewDidLoad];



       favBC = [NSArray arrayWithObjects:@"IDEA1",@"NEW",@"IN VAL...",@"IN ESTI...",@"READY...",@"APPROV...",@"IT

CHAN...",@"UNDER...",@"IMPLEM",@"CLOSED", nil];

       relToMe = [NSArray arrayWithObjects:@"IDEA2",@"NEW",@"IN VAL...",@"IN ESTI...",@"READY...",@"APPROV...",@"IT

CHAN...",@"UNDER...",@"IMPLEM",@"CLOSED", nil];

       repByMe = [NSArray arrayWithObjects:@"IDEA3",@"NEW",@"IN VAL...",@"IN ESTI...",@"READY...",@"APPROV...",@"IT

CHAN...",@"UNDER...",@"IMPLEM",@"CLOSED", nil];

       redForApp = [NSArray arrayWithObjects:@"IDEA4",@"NEW",@"IN VAL...",@"IN ESTI...",@"READY...",@"APPROV...",@"IT

CHAN...",@"UNDER...",@"IMPLEM",@"CLOSED", nil];

       appBC = [NSArray arrayWithObjects:@"IDEA5",@"NEW",@"IN VAL...",@"IN ESTI...",@"READY...",@"APPROV...",@"IT

CHAN...",@"UNDER...",@"IMPLEM",@"CLOSED", nil];

   }



   - (void)didReceiveMemoryWarning {

       [super didReceiveMemoryWarning];

       // Dispose of any resources that can be recreated.

   }



   #pragma mark - Table view data source



   - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {



       return 1;

   }



   - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

   {



       if([_businessName isEqualToString:@"Favorite BC"]){

           return [favBC count];



       }else if ([_businessName isEqualToString:@"Related to me"]){

           return [relToMe count];



       }else if ([_businessName isEqualToString:@"Reported by me"]){

           return [repByMe count];



       }else if ([_businessName isEqualToString:@"Ready for approval"]){

           return [redForApp count];



       }else if ([_businessName isEqualToString:@"Approved BC"]){

           return [appBC count];

       }



       return 0;



   }





   - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

   {

       static NSString *simpleTableIdentifier = @"Business2Cell";



       UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier

forIndexPath:indexPath];

       if(cell == nil){

           cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault

reuseIdentifier:simpleTableIdentifier];

       }

       if([_businessName isEqualToString:@"Favorite BC"]){

           cell.textLabel.text = [favBC objectAtIndex:indexPath.row];



       }else if ([_businessName isEqualToString:@"Related to me"]){

           cell.textLabel.text = [relToMe objectAtIndex:indexPath.row];



       }else if ([_businessName isEqualToString:@"Reported by me"]){

           cell.textLabel.text = [repByMe objectAtIndex:indexPath.row];



       }else if ([_businessName isEqualToString:@"Ready for approval"]){

           cell.textLabel.text = [redForApp objectAtIndex:indexPath.row];



       }else if ([_businessName isEqualToString:@"Approved BC"]){

           cell.textLabel.text = [appBC objectAtIndex:indexPath.row];



       }





       // Configure the cell...



       return cell;

   }





   /*

   // Override to support conditional editing of the table view.

   - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {

       // Return NO if you do not want the specified item to be editable.

       return YES;

   }

   */



   /*

   // Override to support editing the table view.

   - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle

forRowAtIndexPath:(NSIndexPath *)indexPath {

       if (editingStyle == UITableViewCellEditingStyleDelete) {

           // Delete the row from the data source

           [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];

       } else if (editingStyle == UITableViewCellEditingStyleInsert) {

           // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view

       }   

   }

   */



   /*

   // Override to support rearranging the table view.

   - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath

toIndexPath:(NSIndexPath *)toIndexPath {

   }

   */



   /*

   // Override to support conditional rearranging of the table view.

   - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {

       // Return NO if you do not want the item to be re-orderable.

       return YES;

   }

   */





   #pragma mark - Navigation



   // In a storyboard-based application, you will often want to do a little preparation before navigation

   - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

       // Get the new view controller using [segue destinationViewController].

       // Pass the selected object to the new view controller.



       if([segue.identifier isEqualToString:@"collectDetail"])

       {

           NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];



           CollectionViewController *destViewController = segue.destinationViewController;



           if([_businessName isEqualToString:@"Favorite BC"]){

               destViewController.businessName2 = [favBC objectAtIndex:indexPath.row];



           }else if ([_businessName isEqualToString:@"Related to me"]){

               destViewController.businessName2 = [relToMe objectAtIndex:indexPath.row];



           }else if ([_businessName isEqualToString:@"Reported by me"]){

               destViewController.businessName2 = [repByMe objectAtIndex:indexPath.row];



           }else if ([_businessName isEqualToString:@"Ready for approval"]){

               destViewController.businessName2 = [redForApp objectAtIndex:indexPath.row];



           }else if ([_businessName isEqualToString:@"Approved BC"]){

               destViewController.businessName2 = [appBC objectAtIndex:indexPath.row];

           }



           destViewController.title = destViewController.businessName2;



       }

   }





   @end



   code for CollectionViewController.h





   #import <UIKit/UIKit.h>



   @interface CollectionViewController : UICollectionViewController



   @property(nonatomic, strong) NSString *businessName2;



   @end


   code for CollectionViewCell.h



   #import <UIKit/UIKit.h>



   @interface CollectionViewCell : UICollectionViewCell



   @property (weak, nonatomic) IBOutlet UILabel *bcRequestLabel;



   @end



   code for CollectionViewCell.m



   #import "CollectionViewCell.h"



   @implementation CollectionViewCell



   @end





   <b>and the error:<b>



       2015-08-13 15:45:37.500 WACProject2[4049:82472] -[UICollectionViewCell bcRequestLabel]: unrecognized selector sent to instance 0x7fb031f59ab0

   2015-08-13 15:45:37.503 WACProject2[4049:82472] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:

'-[UICollectionViewCell bcRequestLabel]: unrecognized selector sent to instance 0x7fb031f59ab0'

   *** First throw call stack:

   (

   0   CoreFoundation                      0x0000000110722f35 __exceptionPreprocess + 165

   1   libobjc.A.dylib                     0x00000001103bbbb7 objc_exception_throw + 45

   2   CoreFoundation                      0x000000011072a04d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205

   3   CoreFoundation                      0x000000011068227c ___forwarding___ + 988

   4   CoreFoundation                      0x0000000110681e18 _CF_forwarding_prep_0 + 120

   5   WACProject2                         0x000000010fe8be7b -[CollectionViewController collectionView:cellForItemAtIndexPath:] + 187

   6   UIKit                               0x000000011113d41b -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:]

+ 244

   7   UIKit                               0x000000011113eb54 -[UICollectionView _updateVisibleCellsNow:] + 3445

   8   UIKit                               0x0000000111142801 -[UICollectionView layoutSubviews] + 243

   9   UIKit                               0x0000000110b88973 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 521

   10  QuartzCore                          0x00000001143fdde8 -[CALayer layoutSublayers] + 150

   11  QuartzCore                          0x00000001143f2a0e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380

   12  QuartzCore                          0x00000001143f287e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24

   13  QuartzCore                          0x000000011436063e _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242

   14  QuartzCore                          0x000000011436174a _ZN2CA11Transaction6commitEv + 390

   15  QuartzCore                          0x0000000114361db5 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 89

   16  CoreFoundation                      0x0000000110657dc7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23

   17  CoreFoundation                      0x0000000110657d20 __CFRunLoopDoObservers + 368

   18  CoreFoundation                      0x000000011064db53 __CFRunLoopRun + 1123

   19  CoreFoundation                      0x000000011064d486 CFRunLoopRunSpecific + 470

   20  GraphicsServices                    0x0000000113cf19f0 GSEventRunModal + 161

   21  UIKit                               0x0000000110b0f420 UIApplicationMain + 1282

   22  WACProject2                         0x000000010fe8c3e3 main + 115

   23  libdyld.dylib                       0x0000000112cb2145 start + 1

   24  ???                                 0x0000000000000001 0x0 + 1

   )

   libc++abi.dylib: terminating with uncaught exception of type NSException
Bhavesh Nayi
  • 3,626
  • 1
  • 27
  • 42
Shahriat Hossain
  • 340
  • 4
  • 12
  • 1
    Please post your code to show how you are passing data from second TableViewController to CollectionViewController and also post the exception that you are getting. – Homam Aug 13 '15 at 06:14
  • Here I am getting the exception: libc++abi.dylib: terminating with uncaught exception of type NSException – Shahriat Hossain Aug 13 '15 at 06:18
  • Add the entire Exception log. – Mayur Deshmukh Aug 13 '15 at 06:24
  • Without code it is hard to guess what might have caused the error. See if this link helps: http://stackoverflow.com/questions/26442414/libcabi-dylib-terminating-with-uncaught-exception-of-type-nsexception-lldb – Homam Aug 13 '15 at 06:26
  • I have updated my post! – Shahriat Hossain Aug 13 '15 at 06:34
  • what data type is "businessName" and property of businessName? – Gaurav Patel Aug 13 '15 at 06:40
  • can you post your code of collectionVC as well ? check if there is property names BuisenessName? – Misha Aug 13 '15 at 06:44
  • well I have added this property both on SecondTableViewController.h and CollectionViewController.h file because I want to use it on both of them @property(nonatomic, strong) NSString *businessName; – Shahriat Hossain Aug 13 '15 at 06:45
  • CollectionViewController.m is intact, I still didn't work on it before come to this page I am getting the above exception. – Shahriat Hossain Aug 13 '15 at 06:50
  • It seems that when I comment the (void)prepareForSegue method on SendcondTableViewController then it is pushing to the CollectionViewController without any exception. So I think there have problem on that method. – Shahriat Hossain Aug 13 '15 at 07:01
  • When I debug the segue method I found the problem is here: if([_businessName isEqualToString:@"Favorite BC"]){ destViewController.businessName2 = [favBC objectAtIndex:indexPath.row]; } after coming to this portion of code destViewController.businessName2 = [favBC objectAtIndex:indexPath.row]; the execution is terminating. – Shahriat Hossain Aug 13 '15 at 07:08
  • check your segue destination view controller class name with below code.. NSLog(@"%@",NSStringFromClass([segue.destinationViewController class])); is this "CollectionViewController"??????? – Gaurav Patel Aug 13 '15 at 09:24

3 Answers3

2
-[UICollectionViewCell bcRequestLabel] unrecognized selector sent to instance…

You are accessing the bcRequestLabel of a UICollectionViewCell, which does not exist.

Make sure you correctly set the custom class in your collection view cell from the storyboard.

Crazyrems
  • 2,551
  • 22
  • 40
1

The error is because you are indicating that the destination viewController class is CollectionViewController, but the CollectionViewController doesn't implement a businessName. Instead of CollectionViewController, you should indicate your custom class which implements businessName.

CarlosGz
  • 396
  • 2
  • 6
  • Still have the same problem. I have updated my post again with those codes. – Shahriat Hossain Aug 13 '15 at 10:04
  • I think that this is a new error different that the one you posted before. Can you post your code in Github or in a glist? It's hard to read due to indentation – CarlosGz Aug 13 '15 at 13:33
1

Assign class name of destination view controller CollectionViewController in story board like enter image description here

Gaurav Patel
  • 957
  • 1
  • 6
  • 16