【发布时间】:2011-10-29 17:36:49
【问题描述】:
我刚开始使用 X-Code 4.2 构建应用程序。我使用单视图应用程序模板创建了应用程序。
我创建了一个 MainIconViewController,它是一个包含图像、标签和按钮的简单 VC。我将 MainIconViewController 视图添加到我的 mainViewController 视图中,当按下按钮时,我在 Main.m 中出现崩溃,上面写着:
-[__NSCFType mainButtonPressed:]:无法识别的选择器发送到实例 0xb867ba0
Main.m 中发生崩溃的行是:
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
现在 buttonPressed: 完全是空的。
任何想法如何解决这个问题?
我刚刚尝试制作一个全新的项目来重新测试它。我创建了项目,创建了一个包含单个按钮的 viewController 子类。然后我在主视图控制器中创建该视图的一个实例并将其添加到视图中。当我按下按钮时,应用程序就像以前一样崩溃。
编辑: 这是所有代码:
//MainIconViewController.h
@protocol MainIconViewControllerDelegate <NSObject>
-(void) openFileNamed:(NSString *)name;
-(void) createNewFile;
@end
#import <UIKit/UIKit.h>
@interface MainIconViewController : UIViewController {
}
@property (assign) id <MainIconViewControllerDelegate> delegate;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
- (void)mainButtonPressed:(id)sender;
@end
//////////////////////////////
//MainIconViewController.m
#import "MainIconViewController.h"
@implementation MainIconViewController
@synthesize titleLabel;
@synthesize imageView;
@synthesize delegate;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewDidUnload
{
[self setTitleLabel:nil];
[self setImageView:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
- (void)mainButtonPressed:(id)sender{
}
@end
【问题讨论】:
-
其实崩溃不在main()中,贴一下按钮动作代码。
-
按钮动作中什么都没有
标签: iphone ios xcode ipad crash