我有一个名为 vc0 的视图控制器,其显示如下:
[self presentViewController: vc1 animated: YES completion: nil];
在 vc1 中,我有一个按钮来呈现另一个视图控制器:
[self presentViewController: vc2 animated: YES completion: nil];
然后在 vc2 中,我有一个按钮可以关闭视图控制器:
[self dismissViewControllerAnimated:YES completion: ^{
// over here I call one method in vc1
}
正如预期的那样,它返回到 vc1.. 但是 vc1 中有一个按钮可以通过关闭视图控制器返回到 vc0,如下所示:
[self dismissViewControllerAnimated:YES completion:nil];
但由于某种原因它不起作用,视图控制器不会被退回到 vc0。当我第一次呈现 vc1 时,我可以按下按钮来关闭视图控制器,它就可以工作了。但是,当我按下按钮打开 vc2,并且当我将 vc2 关闭回到 vc1,然后按下按钮关闭视图控制器时,那就是它不起作用的时候。
抱歉,如果问题有点不清楚,我很难表达我想说的内容。
另外还有一件事:
我尝试更换dismissViewControllerAnimated:
在 vc1 中手动显示 vc0,但随后我在控制台中收到一条日志,显示我正在尝试显示 vc0,但 vc1 的视图不在窗口层次结构中。这是什么意思?
感谢帮助!
UPDATE:
在这种情况下,VC0 是MenuMileIndexViewController
- VC1 是FlightViewController
- VC2 是BookmarksTableViewController
下面是涉及到的代码:
菜单里程索引视图控制器:
- (IBAction)goToOriginPage {
FlightRecorder *origin = [[FlightRecorder alloc] init];
[self presentViewController:origin animated:YES completion:nil];
}
飞行记录仪:
- (void)searchBarBookmarkButtonClicked:(UISearchBar *)searchBar {
[self bringUpBookmarkkTable];
}
- (void) bringUpBookmarkkTable {
BookmarkTableViewController *bookmarkTVC = [[BookmarkTableViewController alloc] init];
[bookmarkTVC setModalTransitionStyle: UIModalTransitionStyleFlipHorizontal];
[self presentViewController:bookmarkTVC animated:YES completion:nil];
}
- (IBAction)cancel {
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)endBookmarkProcessWithBookmarkCollection: (NSDictionary *)dict {
presetBookmarkContext = [dict mutableCopy];
bookmarkMode = YES;
NSString *compiledText = nil;
NSNumber *number1 = [NSNumber numberWithInt: 1];
if ([dict objectForKey: @"bookmarkTag"] == number1) {
compiledText = [NSString stringWithFormat: @"%@ to %@", [dict objectForKey: @"origin"], [dict objectForKey: @"destination"]];
}
else {
compiledText = [NSString stringWithFormat: @"%@ to %@", [dict objectForKey: @"destination"], [dict objectForKey: @"origin"]];
}
compiledText = [compiledText stringByReplacingOccurrencesOfString:@"Origin: " withString:@""];
compiledText = [compiledText stringByReplacingOccurrencesOfString:@"Destination: " withString:@""];
flightContext = [NSDictionary dictionaryWithObjectsAndKeys: [dict objectForKey: @"miles"], @"miles", compiledText, @"location", [[NSUserDefaults standardUserDefaults] objectForKey: @"tempD"], @"date", nil];
NSString *string = [NSString stringWithFormat: @"\nMiles: %.2f\nFlight: %@\nDate: %@", [[dict objectForKey: @"miles"] floatValue], compiledText, [[NSUserDefaults standardUserDefaults] objectForKey:@"tempD"]];
UIAlertView *bvkBookmarkAlertView = [[UIAlertView alloc] initWithTitle:@"Confirmation" message:string delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Add", nil];
[bvkBookmarkAlertView show];
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1) {
[self cancel]; // Even though cancel is an IBAction, IBAction is the same thing as void so it is callable
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1) {
[TheMileIndexViewController addDesiredMilesToIndex: [[flightContext objectForKey: @"miles"] doubleValue]];
[TravelLogViewController addFlight: flightContext];
if (!bookmarkMode) {
if ([checkbox isSelected]) {
[BookmarkHandler uploadBookmark: bookmarkFlightContext];
}
}
}
if (buttonIndex == 0) {
if ([alertView.title isEqualToString: @"Confirmation"]) {
bookmarkMode = NO;
}
}
}
书签TableViewController:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated: YES];
NSDictionary *dict = [[BookmarkHandler bookmarkCollection] objectAtIndex: indexPath.row];
fl = [[FlightRecorder alloc] init];
[self dismissViewControllerAnimated:YES completion:^{
[fl endBookmarkProcessWithBookmarkCollection: dict];
}];
}
现在,我已经在模拟器中创建了应用程序的屏幕录制,显示了问题所在。我可以通过电子邮件将其发送给您以供参考。所以我可以通过电子邮件将其发送给您。