我尝试为iPhone制作一个应用程序,它有一个UITableViewController,每个单元格都是UITableViewCell的对象。每个单元格都有一个按钮。当有人按下按钮时,应该会出现弹出窗口并向他提供信息。 但是我无法管理弹出窗口问题,我在GitHub中查找并找到MJPopupViewController,但它给出了一个exc_bad_access code = 2错误。
有人给我任何帮助吗
答案 0 :(得分:1)
正如Johny的想法,你可以使用UIPopoverController:
@interface YourViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imgSquare;
@property (strong, nonatomic) UIPopoverController *popover;
@end
@implementation YourViewController
- (void)viewDidLoad
{
[super viewDidLoad];
UIViewController *yourController;
self.popover = [[UIPopoverController alloc] initWithContentViewController:yourController];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(showPopover)
name:@"yourNotificationName"
object:nil];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)showPopover
{
[self.popover presentPopoverFromBarButtonItem:self.navigationItem.leftBarButtonItem
permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self
name:@"yourNotificationName"
object:nil];
}
然后,只要点击CustomTableViewCell中的按钮,就会发布通知
- (void)buttonTapped
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"yourNotificationName"
object:self];
//do anything
}
答案 1 :(得分:0)
创建一个UIPopoverController属性以及要显示的yourPopoverController。
self.popover=[[UIPopoverController alloc]initWithContentViewController:yourPopoverController];
self.popover.delegate=self;
点击按钮
编写此代码[self.popover presentPopoverFromBarButtonItem:self.navigationItem.leftBarButtonItem
permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];