0

I have a button on UIViewController on click of that button an UIview gets poped up like alertview which has tableview in it.Now on selection of table cell i would like to segue to the detail viewcontroller

Here's the link to which i refered but none of them worked for me

For alertview i have used (https://github.com/kwent/ios-custom-alertview)

Thanks.

Community
  • 1
  • 1
Hardik Amal
  • 1,283
  • 1
  • 16
  • 23

2 Answers2

1

@yar1vn's answer is right, however, I'll describe more precisely what you need to do.

Custom alert view from your link has a delegate property, which should conform to protocol

@protocol CustomIOS7AlertViewDelegate

- (void)customIOS7dialogButtonTouchUpInside:(id)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;

@end

that means you should implement this method in your UIViewController.

in .h file:

@interface YourViewController : UIViewController <YourViewController>

...

@end

in .m file:

@implementation YourViewController

...

- (void)customIOS7dialogButtonTouchUpInside:(id)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    [self performSegueWithIdentifier:@"YourSegue" sender:nil];
}

and set the delegate when creating alertView:

[alertView setDelegate:self];

@"YourSegue" is the segue from the controller which shows alertView to the detail view controller.

I disagree that you should use UIAlertController, since if your deployment target is iOS 7 (which is reasonable) you should not use new features of iOS 8

EDIT:

if you want to launch segue from tap on table view cell, you should call [self performSegueWithIdentifier:@"YourSegue" sender:nil] from tableView's delegate method -tableView:didSelectRowAtIndexPath:

I assume you have set current view controller as tableView's dataSource and delegate, so add to your view controller

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self performSegueWithIdentifier:@"YourSegue" sender:nil];
}

EDIT 2:

though setting the UIView as delegate is not the best approach, we can handle it :)

I see two solutions:

the first is to add the controller as the property to your view like this:

@interface YourView : UIView <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, weak) YourViewController *parentController;

...

somewhere (probably, in -viewDidLoad) you set this property as

youViewInstance.parentController = self;

and the in view's delegate method call

[self.parentController performSegueWithIdentifier:@"YouSegue" sender:nil]

the second one is to simply set the controller as tableView's delegate and call performSegue: from its method. And you should describe all details more completely :)

medvedNick
  • 4,512
  • 4
  • 32
  • 50
  • but this will work for button click...can u plz tell me how to do with tableview cell selection...?? – Hardik Amal Oct 17 '14 at 11:23
  • i tried this.but it say performsequewithidentifier is not possible in uiview – Hardik Amal Oct 17 '14 at 11:39
  • bro there is no viewdidload in uiviewalert... and i m not able to perform the 2nd step in edit no 2... plz help – Hardik Amal Oct 17 '14 at 14:21
  • also plz check what will be the view instance in [link](https://github.com/kwent/ios-custom-alertview/tree/master/CustomIOS7AlertView/CustomIOS7AlertView/View)... i m not getting it :( – Hardik Amal Oct 17 '14 at 14:29
  • Bro did u get the solution for this?? – Hardik Amal Oct 19 '14 at 11:42
  • @HardikAmal you add this property to the AlertView class and then in view controller's `viewDidLoad`, that is presenting this alert view, set the pointer from view to controller. This means manual changing the code from the link, yeah – medvedNick Oct 20 '14 at 12:55
0

You shouldn't use 3rd party AlertViews anymore. You can use the AlertController provided with iOS 8 SDK.

I don't know how this AlertView works but the readme mentions a delegate. Did you try calling the segue from the delegate method?

Yariv Nissim
  • 13,273
  • 1
  • 38
  • 44