如何修复我点击它时冻结的UI按钮?

时间:2014-01-05 17:45:21

标签: ios uitableview uibutton

我正在使用Xcode 5.0.2,我还在学习如何在iOS中编码。任何帮助都会在这里真正受到赞赏。我的代码。

- (IBAction)btnMenuTapped:(id)sender
{
    if (self.popoverController)
    {
        [self.popoverController dismissPopoverAnimated:YES];
        self.popoverController = nil;
    }
    else
    {
        MainMenuViewController *contentViewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController" bundle:nil];
        contentViewController.delegate = self;

        self.popoverController = [[WEPopoverController alloc] initWithContentViewController:contentViewController];

        self.popoverController.delegate = self;
        self.popoverController.popoverContentSize = contentViewController.view.frame.size;

        [self.popoverController presentPopoverFromRect:[sender frame]
                                                inView:self.view
                              permittedArrowDirections:UIPopoverArrowDirectionDown
                                              animated:YES];

    }
}

@interface MainViewController : UIViewController <LoginDelegate,WEPopoverParentView,PopoverControllerDelegate,MainMenuDelegate,MKMapViewDelegate,UIActionSheetDelegate,UIAccelerometerDelegate, CLLocationManagerDelegate, NSObject>
{
    AppDelegate *appDelegate;
    IBOutlet MKMapView *userMap;
    CLLocationManager *locationManager;

}
@property (strong, nonatomic) IBOutlet UILabel *speedView;
@property(nonatomic) int speedCount;
@property (nonatomic,retain) CLLocationManager *locationManager;
@property (nonatomic, strong) WEPopoverController *popoverController;

+ (NSString *) speedToMPH: (float) value;


- (IBAction)btnMenuTapped:(id)sender;

@end

但是这行代码是我的应用冻结的地方

self.popoverController.popoverContentSize = contentViewController.view.frame.size;

这里是我试图点击按钮的图片 menu button

这就是我在调试区域中得到的内容

self MainViewController * 0x1656d100 0x1656d100 contentViewController MainMenuViewController * 0x1864eef0 0x1864eef0

1 个答案:

答案 0 :(得分:0)

在MainMenuViewController呈现之前,视图控制器的view属性为nil。因此,当您尝试检索其view.frame.size时,它会崩溃。尝试给出预定义的边界。

例如:

 self.popoverController.popoverContentSize = CGSizeMake(320, 500);