我建立一个漫画浏览器的应用程序,即由两个视图控制器,根视图 - 控制主要显示在其中一个用户决定他们想要通过按下一个按钮来读什么可笑的视图。第二个viewController实际上将漫画显示为带有工具栏和顶部标题的uiscrollview。的UIScrollView不切换图像子视图
所以我遇到的问题是,该漫画图像板本身并没有改变无论从那个第一的漫画你去,如果你观看后的第一个选择其他的漫画。的方式我把它,我承认它不完全MVC的,所以请不要恨,反正我的方式将其设置为每漫画的UIScrollView包括JPG图片的x个,其中每个漫画集的图像名称都有一个共同的前缀然后像“funny1.jpg”,“funny2.jpg”,“funny3.jpg”和“soda1.jpg”,“soda2.jpg”,“soda3.jpg”等数字......
so当用户选择一个漫画,以查看在根控制器它使一个呼叫到委托并设置属于该委托(mainDelegate.comicViewController.property)的comicviewcontroller的实例的ivars我设置在相声板的数量,则标题标签的漫画名称以及图像前缀。
的图像变化的数量(或者至少,你可以通过滚动的数量),以及标题的变化,但由于某些原因,图像的任何漫画最初点击的相同。
我立足这个整个应用程序关闭,从苹果的“滚动”的代码示例。
我想如果我添加一个viewWillAppear:(布尔)动画调用comicViewController每次用户点击按钮,将修复它,但它没有,毕竟这是滚动视图布局的位置。
反正这里是从两个控制器的一些代码:
RootController:
-(IBAction) launchComic2{
AppDelegate *mainDelegate = [(AppDelegate *) [UIApplication sharedApplication] delegate];
mainDelegate.myViewController.comicPageCount = 3;
mainDelegate.myViewController.comicTitle.text = @"\"Death by ETOH\"";
mainDelegate.myViewController.comicImagePrefix = @"etoh";
[mainDelegate.myViewController viewWillAppear:YES];
[mainDelegate.window addSubview: mainDelegate.myViewController.view];
comicViewController:
-(void) viewWillAppear:(BOOL)animated {
self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];
// 1. setup the scrollview for multiple images and add it to the view controller
//
// note: the following can be done in Interface Builder, but we show this in code for clarity
[scrollView1 setBackgroundColor:[UIColor whiteColor]];
[scrollView1 setCanCancelContentTouches:NO];
scrollView1.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView1.clipsToBounds = YES; // default is NO, we want to restrict drawing within our scrollview
scrollView1.scrollEnabled = YES;
// pagingEnabled property default is NO, if set the scroller will stop or snap at each photo
// if you want free-flowing scroll, don't set this property.
scrollView1.pagingEnabled = YES;
// load all the images from our bundle and add them to the scroll view
NSUInteger i;
for (i = 1; i <= self.comicPageCount; i++)
{
NSString *imageName = [NSString stringWithFormat:@"%@%d.jpg", self.comicImagePrefix, i];
NSLog(@"%@%d.jpg", self.comicImagePrefix, i);
UIImage *image = [UIImage imageNamed:imageName];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
// setup each frame to a default height and width, it will be properly placed when we call "updateScrollList"
CGRect rect = imageView.frame;
rect.size.height = kScrollObjHeight;
rect.size.width = kScrollObjWidth;
imageView.frame = rect;
imageView.tag = i; // tag our images for later use when we place them in serial fashion
[scrollView1 addSubview:imageView];
[imageView release];
}
[self layoutScrollImages]; // now place the photos in serial layout within the scrollview
}
- (void)layoutScrollImages
{
UIImageView *view = nil;
NSArray *subviews = [scrollView1 subviews];
// reposition all image subviews in a horizontal serial fashion
CGFloat curXLoc = 0;
for (view in subviews)
{
if ([view isKindOfClass:[UIImageView class]] && view.tag > 0)
{
CGRect frame = view.frame;
frame.origin = CGPointMake(curXLoc, 0);
view.frame = frame;
curXLoc += (kScrollObjWidth);
}
}
// set the content size so it can be scrollable
[scrollView1 setContentSize:CGSizeMake((self.comicPageCount * kScrollObjWidth), [scrollView1 bounds].size.height)];
}
任何帮助将这个可以理解。
尼克