我正在构建一个漫画查看器应用程序,它由两个视图控制器组成,根视图控制器基本上显示一个视图,用户可以通过按下按钮来决定他们想要阅读的漫画。第二个viewController实际上将漫画显示为带有工具栏和顶部标题的uiscrollview。
所以我遇到的问题是,如果你在观看第一部漫画之后选择另一部漫画,那么漫画图像面板本身并没有改变。我设置的方式,我承认它不完全是mvc,所以请不要讨厌,无论如何我设置的方式是每个漫画uiscrollview包含x个jpg图像,其中每个漫画集的图像名称都有一个共同的前缀然后是一个像'funny1.jpg','funny2.jpg','funny3.jpg'和'soda1.jpg','soda2.jpg','soda3.jpg'等数字......
因此,当用户选择要在根控制器中查看的漫画时,它会调用委托并在属于委托的comicviewcontroller实例上设置ivars(mainDelegate.comicViewController.property)我设置了面板的数量漫画,标题标签的漫画名称和图像前缀。
图像数量发生变化(或至少可以滚动的数量),标题会发生变化但由于某种原因,图像与您最初点击的漫画相同。
我将整个应用程序基于苹果的“滚动”代码示例。
我想如果我每次用户点击了修复它的按钮时都会向comicViewController添加一个viewWillAppear:(BOOL)动画调用,但事实并非如此,那就是滚动视图的布局。
无论如何,这里是来自两个控制器的一些代码:
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)];
}
任何帮助都会受到赞赏。
尼克
答案 0 :(得分:0)
所以我最终做的只是在委托中创建漫画控制器的多个实例,而不是仅仅重新使用该实例。如果我遇到问题,会更新这个。
尼克