我有其上呈现这样的视图控制器称为VC0:dismissViewController:不工作
[self presentViewController: vc1 animated: YES completion: nil];
而在VC1我有一个按钮来呈现另一视图控制器:在VC2
[self presentViewController: vc2 animated: YES completion: nil];
然后,我有一个按钮关闭视图控制器:
[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时,然后我按下按钮关闭视图控制器,即当它不起作用时。
对不起,如果这个问题有点不清楚,那么说出我想说的话有点难。
另外一两件事:
我试图在VC1手动目前VC0更换dismissViewControllerAnimated:
,但后来我得到一个登录控制台说,我想提出一个VC0但VC1的观点是不是在窗口层次结构。这是什么意思?
感谢您的帮助!
UPDATE:
在本案例VC0 IS MenuMileIndexViewController
- VC1 IS FlightViewController
- VC2 IS BookmarksTableViewController
这里涉及代码:
MenuMileIndexViewController:
- (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;
}
}
}
BookmarksTableViewController:
- (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];
}];
}
现在,我已经创造了模拟器的应用中展示什么问题的屏幕录制。我可以通过电子邮件发送给您以供参考。所以我可以发邮件给你。
写控制台消息 – Baig
如何以及在何处您重新设定按钮的操作? – geraldWilliam
在xib文件中 – MCKapur