//.h
@interface LoginViewController : UIViewController <UIPopoverControllerDelegate>
....
@end
//.m
- (IBAction)popoverTest:(id)sender
{
UIViewController *popoverContent = [[UIViewController alloc] init];
UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
UILabel *nameLabel = [[UILabel alloc] init]; //edited, fixed UILabel allocation
nameLabel.text = @"Person's name";
[nameLabel sizeToFit];
nameLabel.frame = CGRectMake(10, 10, nameLabel.frame.size.width, nameLabel.frame.size.height);
[myView addSubview:nameLabel];
popoverContent.view = myView;
popoverContent.contentSizeForViewInPopover = CGSizeMake(300, 300);
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
popoverController.delegate = self;
[popoverController presentPopoverFromRect:((UIButton *)sender).frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
NSLog(@"ran all code");
}
を私はUIView
を作成し、サブビューとしてラベルを配置し、UIViewController.view
に私の見解を割り当てます。それから、Popover Controllerを作成し、Popover Controllerのサイズを決め、デリゲートを設定してボタンのフレームから提示しました。
私はSIGABRTとアプリのクラッシュを受けます。
紛失しているものがありますか?
編集:私はUILabel
割り当てを修正しました。問題はいつもそこにある。
あなたのIBAction内にブレークポイントを置き、クラッシュする箇所を確認してください。また、[例外]を有効にしてください(http://stackoverflow.com/questions/4961770/run-stop-on-objective-c-exception-in-xcode-4) –