[英]Double Segue IOS
我目前有一個表格視圖,由於某種原因正在產生雙重segue連接。
[首頁]-> [子視圖#2]-> [相同子視圖#3]
當我單擊一行時,它將通過這些發送到第三視圖[#3]。 這是正確的視圖信息,但是我只想走一步[#2]。 當我單擊返回並返回[#2]而不是首頁時,該問題變得很重要。
為了澄清此設置[#2] == [#3]
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSIndexPath *myIndexPath = [self.tableView indexPathForSelectedRow];
NSInteger row = myIndexPath.row;
if ([segue.identifier isEqualToString:@"ShowLocationsTableView"])
{
NSLog(@"PREPARE");
LocationsTableViewController *ViewController = segue.destinationViewController;
ViewController.categoryDetailModel = @[_categoryTitle[row], _categoryImages[row]];
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView == self.tableView) {
// I assume you have 1 section
NSLog(@"DIDSELECTROW");
NSLog(@"INDEX PATH %i", indexPath.row + 1);
NSLog(@"%i", [tableView numberOfRowsInSection:0]);
if (indexPath.row + 1 == [tableView numberOfRowsInSection:0]) {
NSLog(@"ABOUT");
[self performSegueWithIdentifier:@"aboutCat" sender:self];
} else {
NSLog(@"ELSE");
[self performSegueWithIdentifier:@"ShowLocationsTableView" sender:self];
}
}
正如iphonic
所說,沒有理由僅僅為了使用segue而做所有這些開銷。
您可以只編輯didSelect
方法並自己推送視圖控制器。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView == self.tableView) {
UIViewController *viewController = nil;
if (indexPath.row == [tableView numberOfRowsInSection:0] - 1) {
viewController = [self.storyboard instantiateViewControllerWithIdentifier:<#Identifier#>];
//Do any setup needed by casting your viewController.
} else {
viewController = [self.storyboard instantiateViewControllerWithIdentifier:<#Identifier#>];
//Do any setup needed by casting your viewController.
}
[self.navigationController pushViewController:viewController];
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == self.tableView)
{
UIViewController *viewController = nil;
if (indexPath.row == [tableView numberOfRowsInSection:0] - 1) {
viewController = [self.storyboard instantiateViewControllerWithIdentifier:<#Identifier#>];
//Do any setup needed by casting your viewController...
} else {
viewController = [self.storyboard instantiateViewControllerWithIdentifier:<#Identifier#>];
//Do any setup needed by casting your viewController...
}
[self.navigationController pushViewController:viewController];
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.