简体   繁体   中英

Segue From Custom UIView which is alertview to UIViewController

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.

@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 :)

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM