何が起こっているのかよくわかりませんが、ユーザーがボタンを選択したときにサブビューを表示するビューがあります。このサブビューには、ユーザーがこのサブビューをキャンセルして削除するために選択できるボタンもあります。このすべてが発生すると、サブビューを閉じようとするとアプリがクラッシュします。
これは私のコードです:
ボタンが選択されたときにサブビューを表示するメイン ビューから -
-(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 があります。これはすべてコンパイルされますが、サブビューでキャンセル ボタンを選択するとアプリがクラッシュします。これについてはどこにも何も見つかりません。
基本的に、連絡先から「メッセージを送信」を選択したときのようにビューを表示したいと考えています。