gpt4 book ai didi

objective-c - IOS 5.1 ARC无法识别的选择器已发送到实例

转载 作者:行者123 更新时间:2023-12-01 18:27:02 25 4
gpt4 key购买 nike

我一直在寻找类似的问题,但无法弄清楚问题出在哪里,似乎应该可以解决,但给了我错误。

在IOS 5.1 Ipad Stortyboard应用程序中,当用户单击 pop View 时,我有一个右侧的导航栏项目。我有一个工作正常的Popover View ,但是设计不佳,所以我用一个新的Popover类替换了它,现在出现以下错误

-[UIButton view]: unrecognized selector sent to instance 0xa17ba80
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIButton view]: unrecognized selector sent to instance 0xa17ba80'

我已经尝试了以下功能,但到目前为止都没有起作用。当我更改代码时,它会给我类似的错误。
- (IBAction)setColorButtonTapped:(id)sender{
- (void)setColorButtonTapped:(id)sender{
- (IBAction)setColorButtonTapped:(id)sender forEvent:(UIEvent*)event {
- (void)setColorButtonTapped:(id)sender forEvent:(UIEvent*)event {

当然,我已针对 ibaction 无效更改了ti
[backButton2 addTarget:self action:@selector(setColorButtonTapped:) forControlEvents:UIControlEventTouchUpInside];

这是代码
my.h文件
#import <UIKit/UIKit.h>
#import "ColorPickerController.h"

@interface MeetingViewController : UITableViewController<UIApplicationDelegate,UIAlertViewDelegate,DropDownListDelegate,MFMailComposeViewControllerDelegate,EGORefreshTableHeaderDelegate,ColorPickerDelegate>{

UIPopoverController *_popover;
ColorPickerController *_colorPicker;
UIPopoverController *_colorPickerPopover;

}
@property (nonatomic, strong) UIPopoverController *popover;
@property (nonatomic, strong) ColorPickerController *colorPicker;
@property (nonatomic, strong) UIPopoverController *colorPickerPopover;

- (IBAction)setColorButtonTapped:(id)sender;
@end

my.m文件
@synthesize popover = _popover;
@synthesize colorPicker = _colorPicker;
@synthesize colorPickerPopover = _colorPickerPopover;

- (void)viewDidLoad
{
[super viewDidLoad];
//gear button on navigation Bar
UIImage* imageback2 = [UIImage imageNamed:@"ICON - Gear@2x.png"];
CGRect frameimgback2 = CGRectMake(0, 0, 40, 40);

UIButton *backButton2 = [[UIButton alloc] initWithFrame:frameimgback2];
[backButton2 setBackgroundImage:imageback2 forState:UIControlStateNormal];
[backButton2 addTarget:self
action:@selector(setColorButtonTapped:)
forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *btn2 = [[UIBarButtonItem alloc] initWithCustomView:backButton2];
self.navigationItem.rightBarButtonItem = btn2;

}
#pragma mark ColorPickerDelegate

- (void)colorSelected:(NSString *)color {

[self.colorPickerPopover dismissPopoverAnimated:YES];
}

#pragma mark Callbacks

- (IBAction)setColorButtonTapped:(id)sender {
if (_colorPicker == nil) {
self.colorPicker = [[ColorPickerController alloc] initWithStyle:UITableViewStylePlain];
_colorPicker.delegate = self;
self.colorPickerPopover = [[UIPopoverController alloc] initWithContentViewController:_colorPicker];
}
[self.colorPickerPopover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

实用类
ColorPickerController.h
#import <UIKit/UIKit.h>

@protocol ColorPickerDelegate
- (void)colorSelected:(NSString *)color;
@end


@interface ColorPickerController : UITableViewController {
NSMutableArray *_colors;
id<ColorPickerDelegate> __weak _delegate;
}

@property (nonatomic, strong) NSMutableArray *colors;
@property (nonatomic, weak) id<ColorPickerDelegate> delegate;

@end

实用类
ColorPickerController.m
#import "ColorPickerController.h"


@implementation ColorPickerController
@synthesize colors = _colors;
@synthesize delegate = _delegate;

#pragma mark -
#pragma mark Initialization

/*
- (id)initWithStyle:(UITableViewStyle)style {
// Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
if ((self = [super initWithStyle:style])) {
}
return self;
}
*/


#pragma mark -
#pragma mark View lifecycle


- (void)viewDidLoad {
[super viewDidLoad];
self.clearsSelectionOnViewWillAppear = NO;
self.contentSizeForViewInPopover = CGSizeMake(150.0, 140.0);
self.colors = [NSMutableArray array];
[_colors addObject:@"Red"];
[_colors addObject:@"Green"];
[_colors addObject:@"Blue"];
}




- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Override to allow orientations other than the default portrait orientation.
return YES;
}


#pragma mark -
#pragma mark Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [_colors count];
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

// Configure the cell...
NSString *color = [_colors objectAtIndex:indexPath.row];
cell.textLabel.text = color;

return cell;
}




#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (_delegate != nil) {
NSString *color = [_colors objectAtIndex:indexPath.row];
[_delegate colorSelected:color];
}
}


#pragma mark -
#pragma mark Memory management

- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Relinquish ownership any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
// For example: self.myOutlet = nil;
}


- (void)dealloc {
self.delegate = nil;
}

@end

非常感谢帮助,谢谢

最佳答案

您正在使用UIButton作为UIBarButtonItem的customView。这可能是问题所在。
我建议您改用UIBarButtonIteminitWithImage:style:target:action:初始化程序。

关于objective-c - IOS 5.1 ARC无法识别的选择器已发送到实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12604259/

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