简体   繁体   English

UIScrollView不显示iOS7

[英]UIScrollView not showing iOS7

I'm try to add a scrollview totally by code to a modal view, but it doesn't show. 我尝试通过代码将滚动视图完全添加到模式视图,但未显示。 I've tried different ways but I can't see the mistake, Somebody could help me? 我尝试了不同的方法,但看不到错误,有人可以帮助我吗?

here my code: 这是我的代码:

@interface AddWithScrollOrizontal ()<UIScrollViewDelegate>{

    //IBOutlet UIScrollView*scroll;

}
@property (strong, nonatomic) UIScrollView*scroll;

@implementation AddWithScrollOrizontal

@synthesize scroll;

- (void)viewDidLoad
{

 self.scroll = [[UIScrollView alloc]init];

self.scroll.delegate = self;

    if (IS_IPHONE_5) {
        self.scroll.frame = CGRectMake(0, 58, 320, 270);
    }else{
        self.scroll.frame = CGRectMake(0, 20, 320, 270);
    }

    self.scroll.backgroundColor = [UIColor redColor];
    self.scroll.pagingEnabled = YES;
    self.scroll.contentSize =CGSizeMake(1280, 270);


UIView*firstView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 270)];
...
UIView*fourthView = [[UIView alloc]initWithFrame:CGRectMake(960, 0, 320, 270)];

    [self.scroll addSubview:firstView];
    [self.scroll addSubview:secondView];
    [self.scroll addSubview:thirdView];
    [self.scroll addSubview:fourthView];
    [self.view addSubview:self.scroll];
}

You say you're adding it totally by code, but you're making an IBOutlet to scroll. 您说要完全通过代码添加它,但是要使IBOutlet滚动。 Did you create it in IB? 您是否在IB中创建了它? If not, your problem is that you never instantiate the scroll view. 如果不是,那么您的问题是您永远不会实例化滚动视图。 Also, there's no need to create an ivar for scroll, just create the property inside the @interface declaration for your class extension, and refer to it with self.scroll. 另外,不需要为滚动创建ivar,只需在@interface声明中为类扩展创建属性,然后使用self.scroll进行引用即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM