繁体   English   中英

iPhone iOS 6-取消子视图崩溃

[英]iPhone iOS 6 - Dismissing a subview crashes

我不太清楚发生了什么,但是我有一个视图,当用户选择一个按钮时,该视图会显示一个子视图。 然后,该子视图还具有一个按钮,用户可以选择该按钮来取消和删除该子视图。 当所有这些发生时,当您尝试关闭子视图时,我的应用程序崩溃。

这是我的代码:

在选择按钮时,从显示子视图的主视图中-

-(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关闭该子视图。 所有这些都可以编译,但是当我选择子视图上的“取消”按钮时,我的应用程序崩溃了。 我什么都找不到。

从本质上讲,我希望像从联系人中选择“发送消息”时一样显示视图。

正确的方法是在父视图控制器上调用[self presentModalViewController:viewController] ,然后在要隐藏它时调用[self dismissModalViewController]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM