我创建了一个按钮,并为其添加了一个动作,但是一旦调用它,我就收到了这个错误:
-[NSCFDictionary numberButtonClick:]: unrecognized selector sent to instance
0x3d03ac0 2010-03-16 22:23:58.811
Money[8056:207] *** Terminating app
due to uncaught exception
'NSInvalidArgumentException', reason:'*** -[NSCFDictionary numberButtonClick:]: unrecognized selector sent to instance 0x3d03ac0'
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
UIButton *numberButton = [UIButton buttonWithType:UIButtonTypeCustom];
numberButton.frame = CGRectMake(10, 435, 46, 38);
[numberButton setImage:[UIImage imageNamed:@"one.png"] forState:UIControlStateNormal];
[numberButton addTarget:self action:@selector(numberButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview: numberButton];
}
return self;
}
-(IBAction)numberButtonClick:(id)sender{
NSLog(@"---");
}
Run Code Online (Sandbox Code Playgroud) 如何在Xcode中添加异常断点?
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, @"AppController");
[pool release];
return retVal;
}
Run Code Online (Sandbox Code Playgroud)
我的项目随机崩溃在下面的代码中,在谷歌搜索,一些建议添加异常断点.我通过点击源代码行添加了断点.编辑断点不允许我改变类型.如何添加Exception Breakpoint以及添加位置?(在AppDelegate?

我面临一个问题,我不明白其中的原因.例外并没有给我一个理解问题的线索.
我想根据myArray中给出的数据在我的界面修改UILabel的内容.但是,作为我在函数"cellForRowAtIndexPath"中指定的行,程序将触发异常.
这个问题的原因是什么?
@property (strong, nonatomic) NSMutableArray *myArray; //
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[myArray addObject:@{@"field1": @"myfield1"}]
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger) section {
return self.myArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
// Configure the cell...
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
UILabel *myLabel = (UILabel *)[cell viewWithTag:100]; // myLabel is successfully created …Run Code Online (Sandbox Code Playgroud) 我收到以下错误消息,我无法理解为什么它发生,因为我没有使用任何UIImageView.有时我得到同样的错误,但它是一个CALayer?!?
值得一提的是,我有2个nib和2个控制器以及这个代码所在的基本控制器.
编辑:
这是我项目的结构
MainViewController及其笔尖 - nib中的HomeViewController
MainViewController-Landscape及其笔尖 - HomeViewController-Landscape in nib
HomeViewControllerBase - no nib - 存在所有出口和项目配置代码的基类. - 以下两个子课程都使用奥特莱斯. - 奥特莱斯与每个主要笔尖中的控件相关联.
HomeViewController - 从HomeViewControllerBase继承
HomeViewController-Landscape - 从HomeViewControllerBase继承
所以发生的事情是,子类正在尝试释放其基类(其中包含所有出口).我这样设计它是为了避免在不同的方向视图控制器中重复代码.
@implementation MainViewController
- (void)orientationChanged:(NSNotification *)notification
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView)
{
[self presentModalViewController:self.landscapeViewController
animated:YES];
isShowingLandscapeView = YES;
}
else if (UIDeviceOrientationIsPortrait(deviceOrientation) && isShowingLandscapeView)
{
[self dismissModalViewControllerAnimated:YES];
isShowingLandscapeView = NO;
}
}
- (id)init
{
self = [super initWithNibName:@"MainViewController" bundle:nil];
if (self)
{
isShowingLandscapeView = NO;
self.landscapeViewController …Run Code Online (Sandbox Code Playgroud) 任何人都知道我为什么会收到此错误?
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CustomRaisedTabViewController cancel:]: unrecognized selector sent to instance 0x4d321e0'
Run Code Online (Sandbox Code Playgroud)
这是它失败的代码.这是我的CustomTabViewController.单击"取消"按钮时发生错误.
-(IBAction)showPostModalViewController {
PostActionModalViewController *addController = [[PostActionModalViewController alloc]
initWithNibName:@"PostActionModalView" bundle:nil];
// Configure the PostAddViewController. In this case, it reports any
// changes to a custom delegate object.
addController.delegate = self;
// Create the navigation controller and present it modally.
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:addController];
[self presentModalViewController:navigationController animated:YES];
UIBarButtonItem *cancelButton =
[[UIBarButtonItem alloc] initWithTitle: @"Cancel"
style: UIBarButtonItemStylePlain
target: self
action: @selector(cancel:)]; …Run Code Online (Sandbox Code Playgroud) 我正在创建一个示例应用程序,其中我正在读取数据库并将用户图像和名称显示在tableview中.但我得到以下例外
[UIApplication userListMutableArray]: unrecognized selector sent to instance 0x6816330
Run Code Online (Sandbox Code Playgroud)
以下是我的代码片段
AppDelegate *appDelegate = (AppDelegate*)[UIApplication sharedApplication];
if(sqlite3_open([dbPath UTF8String], &database)==SQLITE_OK)
{
const char *sql = "select NAME,IMAGE from user";
sqlite3_stmt *selectstmt;
if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL)==SQLITE_OK)
{
while (sqlite3_step(selectstmt) == SQLITE_ROW) {
UserData *userData = [[UserData alloc] init];
userData.userName = [NSString stringWithUTF8String:(char*)sqlite3_column_text(selectstmt, 0)];
NSData *data = [[NSData alloc] initWithBytes:sqlite3_column_blob(selectstmt, 1) length:sqlite3_column_bytes(selectstmt, 1)];
if(data == nil)
NSLog(@"image not found");
userData.userImage = [UIImage imageWithData:data];
**[appDelegate.userListMutableArray addObject:userData];**
}
}
}
else
{
sqlite3_close(database);
}
Run Code Online (Sandbox Code Playgroud)
[appDelegate.userListMutableArray …
XCode让我疯狂(再次).人们如何使用它?
-[UIViewController look_for_offer:]: unrecognized selector sent to instance 0x4e34220
2011-04-30 18:38:25.207 myApp[8261:40b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController look_for_offer:]: unrecognized selector sent to instance 0x4e34220'
Run Code Online (Sandbox Code Playgroud)
这就是我做的.我按了一个按钮.我点击了按钮,然后转到检查器中的"连接"选项卡.我从触摸事件拖到代码,它自动创建一个空方法和方法标题.这是方法:
- (IBAction)look_for_offer:(id)sender {
}
Run Code Online (Sandbox Code Playgroud)
现在记住,我甚至没有写过.Interface Builder为我生成了它.然而,当我构建并单击按钮时,我收到"无法识别的选择器"错误消息.
它从错误消息中看起来就像他正在尝试将消息look_for_offer发送到UIViewController.我不知道为什么他会这样做.该方法在我看来,它是UIViewController的子类:
@interface ClientSeekingView : UIViewController {
}
- (IBAction)look_for_offer:(id)sender;
Run Code Online (Sandbox Code Playgroud)
我清楚地将动作拖入了类代码,而不是UIViewController.他为什么要尝试向UIViewController发送消息而不是我的类?
我究竟做错了什么?我如何取悦Xcode?
PS:我清理并重建了几次,没有帮助.
MRB
我在选择通知方法时遇到问题.
在init中我已经定义了这个:
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(stopSyncIndicator:) name:IOS_STOP_SYNC_INDICATOR object:nil];
Run Code Online (Sandbox Code Playgroud)
不过,在头文件和相同的实现中都定义了该方法:
-(void)stopSyncIndicator
{
[indicator stopAnimating];
}
Run Code Online (Sandbox Code Playgroud)
但是,当其他班级发布此通知时:
NSNotification *note = [NSNotification notificationWithName:IOS_STOP_SYNC_INDICATOR object:nil];
[[NSNotificationCenter defaultCenter] postNotification:note];
Run Code Online (Sandbox Code Playgroud)
地狱破裂了:
[FTRecordViewController stopSyncIndicator:]: unrecognized selector sent to instance 0x8d3bc00
2013-11-18 13:47:06.994 [1835:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FTRecordViewController stopSyncIndicator:]: unrecognized selector sent to instance 0x8d3bc00'
*** First throw call stack:
(
0 CoreFoundation 0x01bf75e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x018f88b6 objc_exception_throw + 44
2 CoreFoundation 0x01c94903 -[NSObject(NSObject) doesNotRecognizeSelector:] …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用NSCoding协议来读取和写入数据到plist.当我尝试编写[GolfHoles]时,我得到一个例外,它是NSObject的子类.我已经阅读了几个不同方法的帖子,但都没有帮助.
class GolfCourse: NSObject, NSCoding {
var name: String = ""
var location: String = ""
var holes: [GolfHole] = [GolfHole]()
init(holes: [GolfHole]) {
self.holes = holes
}
// MARK: NSCoding Protocol
func encodeWithCoder(aCoder: NSCoder) {
aCoder.encodeObject(name, forKey: "name")
aCoder.encodeObject(location, forKey: "location")
aCoder.encodeObject(holes, forKey: "holes") // exception here
}
required init(coder aDecoder: NSCoder) {
super.init()
name = aDecoder.decodeObjectForKey("name") as! String
location = aDecoder.decodeObjectForKey("location") as! String
holes = aDecoder.decodeObjectForKey("holes") as! [GolfHole]
}
override init() {
super.init()
for var i=0; i<18; i++ …Run Code Online (Sandbox Code Playgroud) ios ×4
objective-c ×4
iphone ×3
arrays ×1
cocoa-touch ×1
debugging ×1
ios-4.2 ×1
ios4 ×1
ios7 ×1
nscoding ×1
selector ×1
swift ×1
uitableview ×1
xcode ×1