页面控件和滚动视图组合



我是iOS中的新程序员。当我试图用分页对ScrollView进行编码时,有一个问题需要解决。我真的不知道我的代码有什么问题。我已经设置了pageEnable,并将页码设置为4当前0。在xib.file中,我创建了4个视图,使scrollview将"委托"连接到"文件所有者"。我的参考链接http://www.iosdevnotes.com/2011/03/uiscrollview-paging/当我运行应用程序时,视图无法分页。谢谢你的帮助。这是我的代码:

//////////我认为viewDidLoad中的for循环存在问题。

进口

@接口ThirdViewController:UIViewController{

IBOutlet UIScrollView *scrollView; 
IBOutlet UIPageControl *pageControl;
IBOutlet UIView *contentOne;
IBOutlet UIView *contentTwo;
IBOutlet UIView *contentThree;
IBOutlet UIView *contentFour;

}

- (IBAction)pageValueChange:(id)sender;
@property(nonatomic,strong) IBOutlet UIScrollView *scrollView;
@property(nonatomic,strong) IBOutlet UIView *contentOne;
@property(nonatomic,strong) IBOutlet UIView *contentTwo;
@property(nonatomic,strong) IBOutlet UIView *contentThree;
@property(nonatomic,strong) IBOutlet UIView *contentFour;
@property(nonatomic,strong) IBOutlet UIPageControl *pageControl;
@property(nonatomic,strong) NSArray *viewArray;
@end


#import "ThirdViewController.h"
@interface ThirdViewController ()<UIScrollViewDelegate>
@end
@implementation ThirdViewController
    @synthesize scrollView,contentOne, contentTwo,contentThree,contentFour,pageControl,viewArray;
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
             self.title = NSLocalizedString(@"Profile", @"Third");// Custom initialization
        }
        return self;
    }
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        viewArray = [[NSArray alloc]initWithObjects:@"contentOne",@"contentTwo",@"contentThree", @"contentFour",nil];
        for (int i =0; i < [viewArray 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];
            [self.scrollView addSubview: subview]; //////how to pass the array object to subview
            [subview removeFromSuperview];
        }
        // Do any additional setup after loading the view from its nib.
        scrollView.contentSize = CGSizeMake(scrollView.frame.size.width *[viewArray count], scrollView.frame.size.height);

    }
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }

    - (IBAction)dismissKeyboard :(id) sender{
       [sender resignFirstResponder];
    }
    - (IBAction)pageValueChange:(id)sender{
        CGRect frame;
        frame.origin.x = self.scrollView.frame.size.width * self.pageControl.currentPage;
        frame.origin.y = 0;
        frame.size = self.scrollView.frame.size;
    }
    #pragma mark -UIScrollView Delegate
    -(void)scrollViewDidScroll:(UIScrollView *)sender{
        CGFloat pageWidth = self.scrollView.frame.size.width;
        int page = floor((self.scrollView.contentOffset.x-pageWidth/2)/pageWidth)+1;
        self.pageControl.currentPage = page;

}
@end        

是否在崩溃的行旁边放置了断点?

相关内容

  • 没有找到相关文章

最新更新