我一直在尋找類似的問題,但無法弄清楚是什麼問題。它似乎應該工作,但它給了我錯誤。IOS 5.1無法識別的選擇器發送到實例
在IOS 5.1 Ipad Stortyboard應用程序中當用戶單擊應該打開的彈窗視圖時,我有一個正確的導航欄項目。我有一個工作酥料餅的看法,但設計並不是很好,所以我現在有一個新的酥料餅類它給了我下面的錯誤
-[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 {
和ofcourse我已經改變了TI以下關於向IBAction爲或無效
[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 - [email protected]"];
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
utilityclass 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
幫助深表感謝,感謝
如果你使用storyboard,爲什麼不從segges中獲益呢? 您可以將按鈕從您的按鈕拖到您希望顯示在彈出窗口中的視圖中,然後選擇「彈出窗口」。我每次都使用它 您只需按住「ctrl」鍵,將連接從按鈕拖到視圖中即可。 – Diwann
當用戶點擊一個列表時,彈出窗口就像下拉列表一樣下拉或彈出而不改變當前視圖,你怎麼用segue實現? –
與任何segues一樣:只需按住鍵盤上的「ctrl」鍵並從按鈕拖動到_colorPicker視圖。 – Diwann