ビューの切り替えが間違っている

私はアプリケーションのテーブルビューから直接画像を表示する必要があります。私はビューコントローラを配置し、ナビゲーションにインポートすることができます。そのピクチャを開くと、すべてがうまく行きました。 問題は、私が最初に空のビューで行った後にもう一度押すことをやり直すと、私は開始位置に戻ります。 誰かが私にキャッチを教えてもらえますか?

Picture View Controllerのコードは次のとおりです。

    #import "PhotoGalleryVC.h"


@implementation PhotoGalleryVC

@synthesize images,tabBar,forward,backward,back,scrollView,imageWindow,titolo;

//The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
       //Custom initialization
        index = 0;
        images = [[NSMutableArray alloc] init];
    }
    return self;
}



// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];

//  UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" 
//                                                                 style:UIBarButtonItemStyleBordered
//                                                                target:self
//                                                                action:nil]; //@sel
//  self.navigationController.navigationItem.backBarButtonItem = backButton;
//  


    CGRect frame = CGRectMake(0, 0, 320, 480);
    scrollView = [[UIScrollView alloc] initWithFrame:frame];
    scrollView.pagingEnabled = NO;
    //frame = CGRectMake(0, 44, 320, 416);
    //imageWindow = [[UIImageView alloc] initWithFrame:frame];
    scrollView.delegate = self;
    scrollView.maximumZoomScale = 4.0;
    scrollView.minimumZoomScale = 1.0;
    //scrollView.zoomScale 
    [scrollView addSubview:imageWindow];
    [scrollView addSubview:tabBar];
    [scrollView addSubview:titolo];
    scrollView.contentSize = CGSizeMake(320, 460);
    [self.view addSubview:scrollView];
    [backward setEnabled:NO];
    [titolo setTextColor:[UIColor whiteColor]];
    //[titolo setText:[NSString stringWithFormat:@"1/%i",[images count]]];
    [titolo setText:[NSString stringWithFormat:@"%i/%i",index+1,[images count]]];
    if ([images count] == 1) [forward setEnabled:NO];
    if([images count] > 0) [self loadImage];
}

- (void)viewDidAppear:(BOOL)animated {
//  [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
}


// Override to allow orientations other than the default portrait orientation.
/*
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
   //Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait || UIInterfaceOrientationLandscapeRight);
}
*/

- (void)didReceiveMemoryWarning {
   //Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

   //Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
   //Release any retained subviews of the main view.
   //e.g. self.myOutlet = nil;
}

#pragma mark -
#pragma mark Metodi Delegate ScrollView

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"began");
}

//metodo delegate per zooming
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
   //return some view that will be scaled
    //[self.scrollView setNeedsDisplay];
    return self.imageWindow;

}
/*
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    NSLog(@"didScroll");
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
    NSLog(@"WillBeginDragging");
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
    NSLog(@"willDecelerate");
}

- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView {
    NSLog(@"should");
    return YES;
}

- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView {
    NSLog(@"didScrollToTop");
}

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView {
    NSLog(@"willDecelerating");
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    NSLog(@"didEndDecelerating");
}

 - (void)scrollViewDidZoom:(UIScrollView *)scrollView {
 NSLog(@"didZoom");
 }

 - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
 NSLog(@"didEndScrollingAnimation");
 }
*/

- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view {
    //NSLog(@"willBeginZoming");
    if (tabBar.hidden == NO) {
        [tabBar setHidden:YES];
        [titolo setHidden:YES];
    }
}

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {
    //NSLog(@"didEndZooming");
    //NSLog(@"scala %f",scale);
    if (scale == 1.0f) {
        [tabBar setHidden:NO];
        [titolo setHidden:NO];
    }
}

#pragma mark -
#pragma mark Metodi Locali

- (void) addImageName:(NSString*)img {

    if (img) {
        [images addObject:[NSString stringWithString:img]];
    }
}

- (IBAction)backAction {
    //[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:NO];
    [self dismissModalViewControllerAnimated:YES];
}

- (IBAction)backwardAction {
    index--;
    if (index == 0) [backward setEnabled:NO];
    if (index < [images count]-1) [forward setEnabled:YES];
    [self loadImage];   
    [titolo setText:[NSString stringWithFormat:@"%i/%i",index+1,[images count]]];
}

- (IBAction)forwardAction {
    index++;
    if ([images count]-1 == index) [forward setEnabled:NO];
    if (index > 0) [backward setEnabled:YES];
    [self loadImage];
    [titolo setText:[NSString stringWithFormat:@"%i/%i",index+1,[images count]]];
}

- (void) loadImage {
     imageWindow.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[images objectAtIndex:index] ofType:nil]];
}    

#pragma mark -



@end

そして、私はそれをナビゲーションで以下のものと呼んでいます:

   - (void) performOnClickedItemAtIndex: (NSIndexPath *)indexPath onTableView: (UITableView *)tableView {

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

    if([cell.textLabel.text isEqualToString:@"Mappa"]){
        NSString *map = @"";
        //central & east coast
        if ([self.title isEqualToString:@"Centro Storico"]) {
            map = @"mappacaorle.jpg";
        }

        if (![map isEqualToString:@""]) {
            PhotoGalleryVC *gallery = [[PhotoGalleryVC alloc] initWithNibName:@"PhotoGalleryVC" bundle:nil];
            [gallery addImageName:map];
            gallery.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
            [self presentModalViewController:gallery animated:YES];

        }
    }


    Navigation *managedObject = (Navigation*) [fetchedResultsController objectAtIndexPath:indexPath];

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"nav_parent_id.intValue == %d", [managedObject.nav_id intValue]];

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Navigation" inManagedObjectContext:managedObjectContext];
    [fetchRequest setEntity:entity];
    [fetchRequest setPredicate:predicate];

    NSError *error;
    NSArray *array = [managedObjectContext executeFetchRequest:fetchRequest error:&error];


    if (array != nil) {
        //NSLog(@"Sub items count=%d", [array count]);

        if ([array count] > 0) {
            NavTableView *navTable = [[NavTableView alloc] initWithStyle:UITableViewStylePlain];
            navTable.title = managedObject.nav_title;

            if ([managedObject.nav_title isEqualToString:@"Calendario Eventi"] == YES) {
                WebViewController *wvc = [[WebViewController alloc] initWithNibName:@"WebViewController" bundle:nil urlStr:@"http://www.jesolo.it/iphone/?lang=ita#home"];
                wvc.title = managedObject.nav_title;
                [self.navigationController pushViewController:wvc animated:YES];

            }else {
                if ([managedObject.nav_title isEqualToString:@"Certified Italian Products"] == YES) navTable.title   = @"C.I.P.";

            navTable.managedObjectContext = self.managedObjectContext;
            navTable.selectQuery = predicate;
            navTable.parentID = indexPath.row; //[managedObject.nav_id intValue];
            navTable.advert = [managedObject.nav_id intValue];
            /*
            navTable.navigationItem.leftBarButtonItem =[[[UIBarButtonItem alloc] initWithTitle:self.title
                                                                                         style:UIBarButtonItemStyleBordered 
                                                                                        target:self 
                                                                                        action:@selector(didBack:)] 
                                                        autorelease];
             */

            [self.navigationController pushViewController:navTable animated:YES];

            [navTable addActiveMap:managedObject.nav_map_name];
            }



        } else {
           //verify Restaurants, then
            NSFetchRequest *request = [[NSFetchRequest alloc] init];
            NSEntityDescription *resEntity = [NSEntityDescription entityForName:@"Restaurant" inManagedObjectContext:managedObjectContext];
            [request setEntity:resEntity];

//          NSString *string1 = [NSString stringWithFormat:@"res_parent CONTAINS '[%d]'", [managedObject.nav_id intValue]];

            NSString *string1 = nil;
            if ([managedObject.nav_title isEqualToString:@"Around Me"])
                string1 = [NSString stringWithFormat:@"res_tags = %d", self.id_tags_arroundme];
            else 
                string1 = [NSString stringWithFormat:@"res_parent CONTAINS '[%d]'", [managedObject.nav_id intValue]];

            //NSLog(@"Predicate=%@", string1);

            NSPredicate *resPredicate = [NSPredicate predicateWithFormat:string1];
            [request setPredicate:resPredicate];

            NSArray *array2 = [managedObjectContext executeFetchRequest:request error:&error];

            BOOL nothing = YES;
            if (array2 != nil) {
                //NSLog(@"Restaurants count=%d", [array2 count]);
                if ([array2 count] > 0) {

                    if ([managedObject.nav_title isEqualToString:@"Around Me"]) {
                        //if section is function Around Me, then load them on mapview

                        if ([NetworkHelper connectedToNetwork] == YES) {
                            AddressController *mapController = [[AddressController alloc] initWithNibName:@"AddressController" bundle:nil withAroundMe:array2] ;
                            mapController.title = managedObject.nav_title;

                            [self.navigationController pushViewController:mapController animated:YES];
                                                    }
                        else{

                            //no network connection
                            UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Caorle Official Mobile Guide" 
                                                                            message:@"No network connections available." 
                                                                           delegate:nil 
                                                                  cancelButtonTitle:@"Close"
                                                                  otherButtonTitles:nil, nil];  
                            [alert show];

                            return;

                        }
                        nothing  = NO;
                    }
                    else{

                        ResTableView *resTable = [[ResTableView alloc] initWithStyle:UITableViewStylePlain];
                        resTable.title = managedObject.nav_title;
                        resTable.managedObjectContext = self.managedObjectContext;
                        resTable.selectQuery = resPredicate;
                        resTable.parentID = indexPath.row; //[managedObject.nav_id intValue];

                        [self.navigationController pushViewController:resTable animated:YES];

                        if (managedObject.nav_html != nil) [resTable addHtmlHeader:managedObject.nav_html];

                                                nothing  = NO;
                    }
                }
            }



            if (nothing == YES) {


                if (managedObject.nav_html != nil) {

                    NSLog(@">> HTML:%@",managedObject.nav_html);

                    if ([managedObject.nav_html hasPrefix:@"{ID}"]) {
                        int res_id = [[managedObject.nav_html substringFromIndex:4] intValue];
                        NSLog(@"DIRECT ID >> %d", res_id);

                        NSFetchRequest* reqForRestaurant = [[NSFetchRequest alloc] init];
                        NSEntityDescription *resEntity2 = [NSEntityDescription entityForName:@"Restaurant" inManagedObjectContext:managedObjectContext];
                        [reqForRestaurant setEntity:resEntity2];

                        NSString *stringRes = [NSString stringWithFormat:@"res_id.intValue == %d", res_id];
                        NSPredicate *resPredicate2 = [NSPredicate predicateWithFormat:stringRes];
                        [reqForRestaurant setPredicate:resPredicate2];

                        NSArray *array3 = [managedObjectContext executeFetchRequest:reqForRestaurant error:&error];


                        //NSLog(@">>>> Gallery:%d", [managedObject.res_gallery intValue]);

                        if (array3 != nil) {
                            //NSLog(@"Restaurants count=%d", [array2 count]);
                            if ([array3 count] == 1) {

                                Restaurant *managedObjectRes = (Restaurant*) [array3 objectAtIndex:0];

                                RestaurantDetails *details = [[RestaurantDetails alloc] initWithStyle:UITableViewStylePlain];
                                details.managedObjectContext = self.managedObjectContext;
                                details.parentID = [managedObject.nav_id intValue];
                                details.title = managedObjectRes.res_title;

                                [details initItemsWithData:managedObjectRes];

                                [self.navigationController pushViewController:details animated:YES];

                            }
                        }


                    } else if ([managedObject.nav_html hasPrefix:@"{view}"]) {

                        if ([[managedObject.nav_html substringFromIndex:6] isEqualToString:@"meteo"]) {

                            Meteo* meteo = [[Meteo alloc] initWithNibName:@"Meteo" bundle:nil];
                            meteo.title = @"Meteo";
                            [self.navigationController pushViewController:meteo animated:YES];
                                                    }

                    } else if ([managedObject.nav_html hasPrefix:@"{YouTube}"]) {

                        [self setUrlToOpen:[managedObject.nav_html substringFromIndex:9]];
                        [self requestUserToAccessNetwork];
                        [tableView deselectRowAtIndexPath:indexPath animated:NO];

                    } else if ([managedObject.nav_html hasPrefix:@"http://"]) {
                        [self requestUserToAccessNetwork];
                        urlToOpen = managedObject.nav_html;
                        currentTitle = managedObject.nav_title;
                        [tableView deselectRowAtIndexPath:indexPath animated:NO];
                        nothing = NO;
                    }
                    else {
                        NavTableView *navTable = [[NavTableView alloc] initWithStyle:UITableViewStylePlain];
                        navTable.title = managedObject.nav_title;
                        navTable.managedObjectContext = self.managedObjectContext;
                        navTable.selectQuery = [NSPredicate predicateWithFormat:@"nav_parent_id.intValue == %d", managedObject.nav_id];//parent id == 0 is ROOT
                        [self.navigationController pushViewController:navTable animated:YES];
                        [navTable addHtmlHeader:managedObject.nav_html];

                    }
                }
            }
        }
    }

    }

最初の外観は次のようなものです:

enter image description here

結果は次のとおりです。

enter image description here

私が戻ろうとすると、それは次のように行きました:

enter image description here

私はこの最後のステップを緩め、最初の写真に直接戻って行きたい。

ソリューションを見つけるために管理します。私は8時間返答することができないので、質問の編集をしています。

performOnClickedItemAtIndexでは代わりに:

 UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

    if([cell.textLabel.text isEqualToString:@"Mappa"]){
        NSString *map = @"";
        //central & east coast
        if ([self.title isEqualToString:@"Centro Storico"]) {
            map = @"mappacaorle.jpg";
        }

        if (![map isEqualToString:@""]) {
            PhotoGalleryVC *gallery = [[PhotoGalleryVC alloc] initWithNibName:@"PhotoGalleryVC" bundle:nil];
            [gallery addImageName:map];
            gallery.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
            [self presentModalViewController:gallery animated:YES];

        }
    }

私はmainの中に次のようなオプションを追加しました:

if (array != nil) {
    //NSLog(@"Sub items count=%d", [array count]);

if ([managedObject.nav_title isEqualToString:@"Mappa"] == YES ||

        [managedObject.nav_title isEqualToString:@"Centro Storico"] == YES) {

        PhotoGalleryVC *pvc = [[PhotoGalleryVC alloc] initWithNibName:@"PhotoGalleryVC" bundle:nil];
        [pvc addImageName:@"mappacaorle.jpg"];
        pvc.modalTransitionStyle = UIModalTransitionStylePartialCurl;
        [self presentModalViewController:pvc animated:YES];

        //[self.navigationController pushViewController:pvc animated:YES];

        return;


} else if ...
0
いつどこで backAction ?を呼び出し、テーブルビューのデリゲートコールバックを投稿できますか?
追加された 著者 Mat,
どのように解決したのかを投稿することは良い習慣です。そうすれば、他の誰かが同じ問題を抱えていると、あなたがしたことから合図を取ることができます。
追加された 著者 Mat,
私は間違いを発見した...提案のおかげで...
追加された 著者 Akosha,
私は質問を編集し、私の仕事を変更しました。
追加された 著者 Akosha,
詳細は不十分です。あなたのやっていることであれば、あなたの説明にtableviewdidselectrowメソッドが表示されません。あなたのtableviewコントローラコードの完全なコードも表示してください。
追加された 著者 SeriousSam,

答えはありません

0