我有其上呈現這樣的視圖控制器稱爲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