Diyavol Pasa
Diyavol Pasa

Reputation: 13

Pop-up View for UITableviewCell in XCode5

I try to make an application for iPhone it has one UITableViewController and every cell is an object of UITableViewCell. And every cell has a button.When someone presses the button a pop up should be appear and give him information. However I cannot manage pop-up issue, I look up in GitHub and find MJPopupViewController but it gives a exc_bad_access code=2 error.

Does any one give me any help about it

Upvotes: 0

Views: 961

Answers (2)

Arilliance
Arilliance

Reputation: 41

As Johny idea, you can use 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];
}

Then post notification whenever the button in your CustomTableViewCell is tapped

- (void)buttonTapped
    {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"yourNotificationName"
                                                            object:self];
        //do anything
    }

Upvotes: 1

johny kumar
johny kumar

Reputation: 1270

create a UIPopoverController property and yourPopoverController which you want to show.

self.popover=[[UIPopoverController alloc]initWithContentViewController:yourPopoverController];
self.popover.delegate=self;

write this code in button click

[self.popover presentPopoverFromBarButtonItem:self.navigationItem.leftBarButtonItem
 permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

Upvotes: 0

Related Questions