First of all segues
can be use only between UIViewControllers
. So in case you want to perform a segue between two views that are on the same view controller, that's impossible.
But if you want to perform a segue between two view controllers and the segue should be trigger by an action from one view (inside first view controller) well that's possible.
So in your case, if I understand the question, you want to perform a segue when the first cell of a UITableView that's inside of a custom UIView
is tapped. The easiest approach would be to create a delegate on your custom UIView
that will be implemented by your UIViewController that contains the custom UIView
when the delegate method is called you should perform the segue, here is a short example:
YourCustomView.h
@protocol YourCustomViewDelegate <NSObject>
-(void)pleasePerformSegueRightNow;
@end
@interface YourCustomView : UIView {
UITableView *theTableView; //Maybe this is a IBOutlet
}
@property(weak, nonatomic) id<YourCustomViewDelegate>delegate;
YourCustomview.m
@implementation YourCustomview
@ synthesise delegate;
//make sure that your table view delegate/data source are set properly
//other methods here maybe
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.row == 0) { //or any other row if you want
if([self.delegate respondsToSelector:@selector(pleasePerformSegueRightNow)]) {
[self.delegate pleasePerformSegueRightNow];
}
}
}
YourTableViewController.h
@interface YourTableViewController : UIViewController <YourCustomViewDelegate> {
//instance variables, outlets and other stuff here
}
YourTableViewController.m
@implementation YourTableViewController
-(void)viewDidLoad {
[super viewDidLoad];
YourCustomView *customView = alloc init....
customView.delegate = self;
}
-(void)pleasePerformSegue {
[self performSegueWithIdentifier:@"YourSegueIdentifier"];
}
You can create any methods to your delegate or you can customise the behaviour, this is just a simple example of how you can do it.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…