从 plist 加载滚动视图
事情是这样的:对于新闻应用程序,我在滚动视图中加载一个视图,以便在每个部分上进行水平分页,没问题,PageControl 演示帮助很大,但现在我需要在另一个滚动中加载视图以编程方式查看,这样我就可以显示每个部分的内容,问题是我需要 NIB 文件上已有的自定义设计视图,因此每个部分看起来都不同,所以我想使用 plist 在通用滚动视图上加载每个自定义视图。
这是我到目前为止得到的:
- (void)loadScrollViewWithPage:(int)page{
if (page < 0)
return;
if (page >= kNumberOfPages)
return;
// replace the placeholder if necessary
Seccion *controller = [viewControllers objectAtIndex:page];
if ((NSNull *)controller == [NSNull null])
{
controller = [[Seccion alloc] initWithPageNumber:page];
[viewControllers replaceObjectAtIndex:page withObject:controller];
[controller release];
}
// add the controller's view to the scroll view
if (controller.view.superview == nil)
{
NSDictionary *numberItem = [self.contentList objectAtIndex:page];
//UIImage *image1 = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image1.jpg" ofType:nil]];
controller.sectionTitle.text = [numberItem valueForKey:Nombre];
controller.sectionView.text = [numberItem objectForKey:Vista];
controller.sectionId.text = [numberItem valueForKey:Id];
//Here is supposed to have the code to load the view inside the scroll view I tried using: [controller.sectionScrollView addSubview:controller.sectionView.text];
CGRect frame = scrollView.frame;
frame.origin.x = frame.size.width * page;
frame.origin.y = 0;
controller.view.frame = frame;
[scrollView addSubview:controller.view];
}
}
非常感谢
here is the deal: For a news app, I'm loading a view inside a Scroll View for horizontal paging on each section, no problem with that, the PageControl demo helped a lot, but now I need to load a View inside another Scroll View programmatically so I can show the content of each section, the deal is that I need custom designed views already on a NIB file so each section looks different, so I would like to use a plist to load each custom view on the generic Scroll View.
Here is what I got until now:
- (void)loadScrollViewWithPage:(int)page{
if (page < 0)
return;
if (page >= kNumberOfPages)
return;
// replace the placeholder if necessary
Seccion *controller = [viewControllers objectAtIndex:page];
if ((NSNull *)controller == [NSNull null])
{
controller = [[Seccion alloc] initWithPageNumber:page];
[viewControllers replaceObjectAtIndex:page withObject:controller];
[controller release];
}
// add the controller's view to the scroll view
if (controller.view.superview == nil)
{
NSDictionary *numberItem = [self.contentList objectAtIndex:page];
//UIImage *image1 = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image1.jpg" ofType:nil]];
controller.sectionTitle.text = [numberItem valueForKey:Nombre];
controller.sectionView.text = [numberItem objectForKey:Vista];
controller.sectionId.text = [numberItem valueForKey:Id];
//Here is supposed to have the code to load the view inside the scroll view I tried using: [controller.sectionScrollView addSubview:controller.sectionView.text];
CGRect frame = scrollView.frame;
frame.origin.x = frame.size.width * page;
frame.origin.y = 0;
controller.view.frame = frame;
[scrollView addSubview:controller.view];
}
}
Thanks a lot in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的所有视图都有自己的 nib,这可能会起作用:
因此您可以将每个 nib 的名称保存在 plist 中。
If all your views have it own nib, this might work:
so you can save the name of each nib in a plist.