我剛開始使用X-Code 4.2開發應用程序。我使用單一視圖應用程序模板創建了該應用程序。按下按鈕後Main.m中的崩潰
我創建了一個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()中,發佈按鈕操作代碼。 – zaph
在按鈕動作中沒有任何內容 – Brodie