我無法弄清楚發生了什麼,但我有一個視圖,當用戶選擇一個按鈕時顯示子視圖。這個子視圖也有一個按鈕,用戶可以選擇取消和刪除這個子視圖。當所有這些都發生時,當您嘗試關閉子視圖時,我的應用程序崩潰。iPhone iOS 6 - 關閉子視圖崩潰
這是我的代碼:
從顯示的子視圖當選擇按鈕主視圖 -
-(IBAction)sendMessage:(id)sender{
NSLog(@"Going to send a message....");
CGRect frameBounds = [self.view bounds];
float frameWidth = frameBounds.size.width;
float frameHeight = frameBounds.size.height;
float frameX = frameBounds.origin.x;
//float frameY = frameBounds.size.height/2;
float frameY = frameBounds.size.height;
float finalY = frameBounds.size.height/1.75;
MessageChooserController *chooser = [[MessageChooserController alloc] initWithNibName:@"MessageChooser" bundle:nil];
//Set the frame off the screen at the bottom
chooser.view.frame = CGRectMake(frameX, frameY, frameWidth, frameHeight);
[self.view addSubview:chooser.view];
[UIView animateWithDuration:0.5 animations:^{chooser.view.frame = CGRectMake(frameX, finalY, frameWidth, frameHeight);}];
}
正如你可以看到這只是顯示出一個新的子視圖 - MessageChooserController。現在這個子視圖,MessageChooserController有一個按鈕來取消這個「動作」。
爲MessageChooserController頭文件:
#import <UIKit/UIKit.h>
@interface MessageChooserController : UIViewController
@property (weak, nonatomic) IBOutlet UIButton *btn_sendEmail;
@property (weak, nonatomic) IBOutlet UIButton *btn_sendText;
@property (weak, nonatomic) IBOutlet UIButton *btn_cancel;
-(IBAction)closeChooser:(id)sender;
@end
及其實施:
#import "MessageChooserController.h"
@interface MessageChooserController()
@end
@implementation MessageChooserController
@synthesize btn_cancel, btn_sendEmail, btn_sendText;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
/*
[btn_cancel setBackgroundImage:[[UIImage imageNamed:@"iphone_delete_button.png"] stretchableImageWithLeftCapWidth:8.0f topCapHeight:0.0f] forState:UIControlStateNormal];
*/
/*
UIImage *cancelButtonImage = [[UIImage imageNamed:@"iphone_delete_button"] resizableImageWithCapInsets:UIEdgeInsetsMake(30,0,30,0)resizingMode:UIImageResizingModeStretch];
[btn_cancel setBackgroundImage:cancelButtonImage forState:UIControlStateNormal];
*/
}
-(IBAction)closeChooser:(id)sender{
[self.view removeFromSuperview];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
正如你可以看到我有一個簡單的方法來關閉這個子視圖,closeChooser。所有這些編譯,但當我選擇子視圖上的取消按鈕我的應用程序崩潰。關於這一點,我找不到任何地方。
本質上,我想有一個視圖顯示,就像它從您的聯繫人中選擇「發送消息」時一樣。
看到崩潰日誌會很有幫助。 – Abizern
如何獲取崩潰日誌? – CodeMoto
它在你的Xcode控制檯中。 – Abizern