Objective c IOS 5.1 ARC无法识别的选择器已发送到实例
我一直在研究类似的问题,但无法找出问题所在。它似乎应该有效,但它给了我错误 在IOS 5.1 Ipad StoryBoard应用程序中,当用户单击弹出视图时,我有一个右导航栏项应该打开。我有一个工作的popover视图,但设计不好,所以我用一个新的popover类替换了它,现在它给了我以下错误Objective c IOS 5.1 ARC无法识别的选择器已发送到实例,objective-c,ios,error-handling,uibutton,popover,Objective C,Ios,Error Handling,Uibutton,Popover,我一直在研究类似的问题,但无法找出问题所在。它似乎应该有效,但它给了我错误 在IOS 5.1 Ipad StoryBoard应用程序中,当用户单击弹出视图时,我有一个右导航栏项应该打开。我有一个工作的popover视图,但设计不好,所以我用一个新的popover类替换了它,现在它给了我以下错误 -[UIButton view]: unrecognized selector sent to instance 0xa17ba80 *** Terminating app due to uncaught
-[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 {
当然,我已经改变了关于iAction或void
[backButton2 addTarget:self action:@selector(setColorButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
这是密码
我的.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
实用类
颜色选择器控制器
#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
非常感谢您的帮助,谢谢您正在使用
ui按钮
作为UIBarButtonItem
的自定义视图。这可能就是问题所在。
我建议您使用
uibarbuttonim
的initWithImage:style:target:action:
初始值设定项。您使用的是uibuttonim
作为uibarbuttonim
的自定义视图。这可能就是问题所在。
我建议您使用
UIBarButtonItem
的initWithImage:style:target:action:
初始值设定项。UIButton是一个视图,因此没有视图属性或实例方法 UIButton是一个视图,因此没有视图属性或实例方法 如果你使用故事板,为什么不从segues中获益?您可以将一段从按钮拖动到要显示在popover中的视图,然后选择“popover”。每次你需要做的就是在按住“ctrl”键的同时将一个连接从你的按钮拖到你的视图上。当用户单击列表下拉或弹出而不更改当前视图时,弹出窗口就像下拉列表一样,你怎么能用segue做到这一点?就像任何segues一样:你只需按住“ctrl”键键,然后从按钮拖动到_colorPicker视图。如果使用故事板,为什么不从segues中获益?您可以将一段从按钮拖动到要显示在popover中的视图,然后选择“popover”。每次你需要做的就是在按住“ctrl”键的同时将一个连接从你的按钮拖到你的视图上。当用户单击列表下拉或弹出而不更改当前视图时,弹出窗口就像下拉列表一样,你怎么能用segue做到这一点?就像任何segues一样:你只需按住“ctrl”键键,然后从按钮拖动到_colorPicker视图。是的,当我将代码更改为uibarbuttoneim*btn3=[[uibarbuttoneim alloc]initWithImage:imageback2 style:nil目标:自操作:@selector(setColorButtonTapped:)]代码>它可以工作,但现在按钮看起来很难看,我如何添加我的自定义样式?如果你想,你仍然可以使用自定义视图;只需使用常规的ui视图
而不是ui按钮
。此外,您还可以尝试使用不同的uibarbuttonimstyle
设置:@MordFustang您不需要将代码更改为uibarbuttonim,而是使用UIButton自定义视图。尝试下面的行[self.colorPickerPover PresentPoOverfromBarbuttonItem:self.navigationItem.rightBarButtonItem permittedArrowDirections:UIPopOverErrorDirection任意动画:YES];是的,当我将代码更改为uibarbuttoneim*btn3=[[uibarbuttoneim alloc]initWithImage:imageback2样式:nil目标:自我操作:@selector(setColorButtonTapped:)]代码>它可以工作,但现在按钮看起来很难看,我如何添加我的自定义样式?如果你想,你仍然可以使用自定义视图;只需使用常规的ui视图
而不是ui按钮
。此外,您还可以尝试使用不同的uibarbuttonimstyle
设置:@MordFustang您不需要将代码更改为uibarbuttonim,而是使用UIButton自定义视图。尝试下面的行[self.colorPickerPover PresentPoOverfromBarbuttonItem:self.navigationItem.rightBarButtonItem permittedArrowDirections:UIPopOverErrorDirection任意动画:YES];
#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
#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