Reputation: 2809
I have a custom view controller with a custom segue.
When I try to launch the application it crashes with an 'NSInvalidArgumentException', reason: '-[UtilizationVC setUtilizationManager:]: unrecognized selector sent to instance
error immediately.
The breakpoint throws at the following line which is in my AppDelegate
inside of the didFinishLaunchingWithOptions
method.
LINE REFERENCED: utilizationVC.utilizationManager = self.utilizationManager;
My related classes .m and .h files:
UtilizationVC.h:
@class UtilizationVC;
@protocol UtilizationVCDelegate <NSObject>
- (void)UtilizationVCDidCancel: (UtilizationVC *)controller;
- (void)UtilizationVCDidDelete: (UtilizationVC *)controller;
- (void)UtilizationVCDidSave: (UtilizationVC *)controller;
@end
@interface UtilizationVC : UITableViewController <UITextFieldDelegate, UIActionSheetDelegate>
@property (weak, nonatomic) IBOutlet UIBarButtonItem *doneButton;
@property (weak, nonatomic) id <UtilizationVCDelegate> delegate;
@property (strong, nonatomic) NSString *identifier;
@property (strong, nonatomic) NSIndexPath *indexPath;
- (IBAction)cancel:(id)sender;
- (IBAction)done:(id)sender;
@end
UtilizationVC.m:
#import "UtilizationVC.h"
@interface UtilizationVC ()
@end
@implementation UtilizationVC
{
UIColor *custom1;
UIColor *custom2;
UIColor *custom3;
UIColor *custom4;
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
custom1 = [UIColor whiteColor];
custom2 = [UIColor darkGrayColor];
custom3 = [UIColor blackColor];
//custom4 = [UIColor colorWithRed:1.0 green:.925 blue:.5451 alpha:1.0];
//custom4 = [UIColor colorWithRed:.7843 green:.7451 blue:.3725 alpha:1.0];
custom4 = [UIColor colorWithRed:.97 green:.97 blue:.588 alpha:1.0];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = self.view.bounds;
gradient.colors = [NSArray arrayWithObjects:(id)[custom2 CGColor], (id)[custom1 CGColor], (id)[custom2 CGColor], nil];
gradient.startPoint = CGPointMake(0.5, 0);
gradient.endPoint = CGPointMake(0.5, 1.0);
gradient.locations = [NSArray arrayWithObjects: [NSNumber numberWithFloat:0.0], [NSNumber numberWithFloat:0.5], [NSNumber numberWithFloat:1.0], nil];
UIView *view = [[UIView alloc] initWithFrame:self.tableView.frame];
[view.layer insertSublayer:gradient atIndex:0];
self.tableView.backgroundView = view;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
// Return the number of rows in the section.
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
return cell;
}
@end
UtilizationManager.h:
#import <UIKit/UIKit.h>
#import "UtilizationVC.h"
@interface UtilizationManagerVC : UITableViewController
@property (weak,nonatomic) UtilizationManagerVC* utilizationManager;
@end
UtilizationManager.m:
#import "UtilizationManagerVC.h"
@interface UtilizationManagerVC ()
@end
@implementation UtilizationManagerVC
@synthesize utilizationManager = _utilizationManager;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
UIColor *custom1 = [UIColor whiteColor];
UIColor *custom2 = [UIColor darkGrayColor];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = self.view.bounds;
gradient.colors = [NSArray arrayWithObjects:(id)[custom2 CGColor], (id)[custom1 CGColor], (id)[custom2 CGColor], nil];
gradient.startPoint = CGPointMake(0.5, 0);
gradient.endPoint = CGPointMake(0.5, 1.0);
gradient.locations = [NSArray arrayWithObjects: [NSNumber numberWithFloat:0.0], [NSNumber numberWithFloat:0.5], [NSNumber numberWithFloat:1.0], nil];
UIView *view = [[UIView alloc] initWithFrame:self.tableView.frame];
[view.layer insertSublayer:gradient atIndex:0];
self.tableView.backgroundView = view;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
// Return the number of rows in the section.
return 0;
}
@end
I am not sure as to why this is breaking on launch as it was a simple copypaste from another story board and a simple change of the name of the header files.
EDIT:
UINavigationController *utilizationNavController = [[tabBarController viewControllers] objectAtIndex:6];
UtilizationManagerVC *utilizationVC = [[utilizationNavController viewControllers]objectAtIndex0];
utilizationVC.utilizationManager = self.utilizationManager;
ERROR THROWN HERE this utilizationVC is of type UtilizationManagerVC poor naming on whoever programmed this chunk.
Upvotes: 0
Views: 659
Reputation: 17687
You are setting the utilizationManager
instance in your UtilizationVC
, but you don't have any property in that class. For this reason the app crashes.
I think you commit an error because you put the property:
@property (weak,nonatomic) UtilizationManagerVC* utilizationManager;
in the UtilizationManagerVC
..so a class that has as property an object typed with the same class?? Maybe you want put this property in your UtilizationVC
.
Other cool suggests:
Your utilizationManager
property should be strong
, for what particular reason are you using weak
?
If you declare a @property
, you don't need to synthesize
it, because is authosynthesized
with the name _nameProperty
. So until when you don't want use another name, you don't need to @synthesize
a @proeprty
.
Upvotes: 1