gpt4 book ai didi

ios - 将 View Controller 添加到选项卡栏 Controller 后发送到实例的无法识别的选择器

转载 作者:行者123 更新时间:2023-11-29 02:58:16 25 4
gpt4 key购买 nike

我有一个带有自定义转场的自定义 View Controller 。

当我尝试启动应用程序时,它因 'NSInvalidArgumentException' 崩溃,原因:'-[UtilizationVC setUtilizationManager:]: 无法识别的选择器发送到实例立即出错。

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

引用行:utilizationVC.utilizationManager = self.utilizationManager;

我的相关类 .m 和 .h 文件:

利用VC.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

利用VC.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;
}

@结束

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;
}

@结束

我不确定为什么这会在发布时中断,因为它是来自另一个 Storyboard的简单复制粘贴和头文件名称的简单更改。

编辑:

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

此处抛出错误这个 utilizationVC 是 UtilizationManagerVC 类型,无论谁编程这个 block ,命名都很糟糕。

最佳答案

您正在 UtilizationVC 中设置 utilizationManager 实例,但您在该类中没有任何属性。由于这个原因,应用程序崩溃了。

我认为您犯了一个错误,因为您放置了属性:

@property (weak,nonatomic) UtilizationManagerVC* utilizationManager;

UtilizationManagerVC中..所以一个类具有使用同一类键入的对象作为属性?也许您想将此属性放入您的 UtilizationVC 中。

其他很酷的建议:

  • 您的 utilizationManager 属性应该是strong,您出于什么特殊原因使用weak

  • 如果您声明了 @property,则无需synthesize 它,因为 authosynthesized 的名称为 _nameProperty。因此,直到您不想使用其他名称时,您都不需要 @synthesize@proeprty

关于ios - 将 View Controller 添加到选项卡栏 Controller 后发送到实例的无法识别的选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23620193/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com