ios - 无法在 Storyboard iOS 中附加 UIScrollView Paging

标签 ios objective-c uiscrollview scroll-paging

我有一个使用 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/

相关文章:

ios - uiview仅渲染特定区域的xcode(不通过裁剪)

ios - 选择 UITextField 时如何显示 UIPickerView

ios - 指定NSLayoutConstraint的UILayoutPriority好像没有生效

ios - 当更改 Iphone 屏幕时,内容不适合 iPad 屏幕

ios - 从 UITabBarController 加载 View Controller 时出现问题

ios - 将 UIScrollView 适配到 UIView

ios - 编辑 UITextField 时正在重置 UIScrollView

ios - 如何将 iOS ui 控件分组到面板中?

iphone - iOS - 从服务器接收二进制数据仅适用于 Debug模式

iphone - 将 uiview 转换为 .png 图片