Iphone 交换观点是错误的
我需要在应用程序中直接从表视图显示图片。我设法放置视图控制器并将其导入导航,当我打开图片时,一切都很好。 问题是,当我尝试返回时,它首先在空视图上返回,然后再次按下“返回”,我返回到起始位置。 有人能告诉我怎么抓吗 以下是图片视图控制器的代码:Iphone 交换观点是错误的,iphone,objective-c,cocoa-touch,Iphone,Objective C,Cocoa Touch,我需要在应用程序中直接从表视图显示图片。我设法放置视图控制器并将其导入导航,当我打开图片时,一切都很好。 问题是,当我尝试返回时,它首先在空视图上返回,然后再次按下“返回”,我返回到起始位置。 有人能告诉我怎么抓吗 以下是图片视图控制器的代码: #import "PhotoGalleryVC.h" @implementation PhotoGalleryVC @synthesize images,tabBar,forward,backward,back,scrollView,ima
#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
开始时的外观如下所示:
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 ...
结果是:
当我试图回到过去时,我想到:
我想放松最后一步,直接回到第一张图片
设法找到解决办法。我不能回答8小时,所以做编辑的问题
在PerformMonClickEditeMatIndex中,改为:
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结构中添加了如下选项:
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 ...
细节不充分。如果你是这样做的,我在你的描述中没有看到tableviewdidselectrow方法。请同时显示tableview控制器代码的完整代码。何时/何地调用<代码>回退操作<代码>?…您可以发布tableview代理回退吗?我发现错误。。。谢谢你的建议…这是一个很好的做法,张贴你是如何解决的,这样如果其他人有同样的问题,可以从你所做的事情中得到提示。我编辑了问题并提供了我所做的更改。