将视图控制器添加到选项卡栏控制器后,将无法识别的选择器发送到实例

时间:2014-05-12 22:50:23

标签: ios objective-c uitabbarcontroller custom-view unrecognized-selector

我有一个带有自定义segue的自定义视图控制器。

当我尝试启动应用程序时,它会以'NSInvalidArgumentException', reason: '-[UtilizationVC setUtilizationManager:]: unrecognized selector sent to instance崩溃 立即出错。

断点在AppDelegate方法内didFinishLaunchingWithOptions内的以下行处抛出。

LINE REFERENCED:utilizationVC.utilizationManager = self.utilizationManager;

我的相关课程.m和.h文件:

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

我不确定为什么这会在发布时中断,因为它是来自另一个故事板的简单copypaste以及头文件名称的简单更改。

编辑:

UINavigationController *utilizationNavController = [[tabBarController viewControllers] objectAtIndex:6];
   UtilizationManagerVC *utilizationVC = [[utilizationNavController viewControllers]objectAtIndex0];
utilizationVC.utilizationManager = self.utilizationManager;

这里的错误 这个utilizationVC属于UtilizationManagerVC类型,无论是谁编程这个块都是不好的命名。

1 个答案:

答案 0 :(得分:1)

您在utilizationManager中设置了UtilizationVC个实例,但您在该课程中没有任何属性。因此,应用程序崩溃了。

我认为你提交了一个错误,因为你把属性:

@property (weak,nonatomic) UtilizationManagerVC* utilizationManager;

UtilizationManagerVC ..所以一个类具有作为属性的对象键入相同的类?也许你想把这个属性放在UtilizationVC

其他很酷的建议:

  • 您的utilizationManager媒体资源应为strong,因为您使用weak的具体原因是什么?

  • 如果您声明@property,则不需要synthesize,因为authosynthesized的名称为_nameProperty。因此,在您不想使用其他名称之前,您不需要@synthesize @proeprty