我有一个使用 Storyboard 构建的表格应用程序,因此我想为表格中的项目添加分页可能性。我用过this tutorial :
因此,我将新 View 添加到 Storyboard 中,并将 UIScrollView 添加到 View 上。比制作一个属性 UIScrollView*scrollView;并在 Storyboard 中建立关系scrollView - ECOCOMlPanelPagingViewController。 (ECOMClPanelPagingViewController 是我的 View 的 UIViewController 类。
.h
#import <UIKit/UIKit.h>
@interface ECOMClPanelPagingViewController : UIViewController
{
UIScrollView *scrollView;
}
@property (nonatomic, retain) IBOutlet UIScrollView* scrollView;
@end
.m
#import "ECOMClPanelPagingViewController.h"
@interface ECOMClPanelPagingViewController ()
@end
@implementation ECOMClPanelPagingViewController
@synthesize scrollView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSArray *colors = [NSArray arrayWithObjects:[UIColor redColor], [UIColor greenColor], [UIColor blueColor], nil];
for (int i = 0; i < colors.count; i++) {
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * i;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
UIView *subview = [[UIView alloc] initWithFrame:frame];
subview.backgroundColor = [colors objectAtIndex:i];
[self.scrollView addSubview:subview];
[subview release];
}
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * colors.count, self.scrollView.frame.size.height);
}
- (void)viewDidUnload
{
self.scrollView = nil;
}
- (void)dealloc
{
[scrollView release];
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
@end
所以我只看到带有导航 Controller 的白色背景。谁可以帮助我?
最佳答案
只需取消选中“使用自动布局”选项即可
关于ios - 无法在 Storyboard iOS 中附加 UIScrollView Paging,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15806562/