Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 具有2个视图的UIScrollView分页_Objective C_Ios_Ios5_Uiscrollview - Fatal编程技术网

Objective c 具有2个视图的UIScrollView分页

Objective c 具有2个视图的UIScrollView分页,objective-c,ios,ios5,uiscrollview,Objective C,Ios,Ios5,Uiscrollview,我尝试使用本教程中的两个视图实现分页: 我想通过将UIScrollView放入页面并在每个页面中使用新内容更新来修改此内容: -(void)addContent:(NSString*)txt{ int size = 5; UITextView *txtView; int row = 0; //from left int xPlace = 0; //space between row's int rowSpace = 20;

我尝试使用本教程中的两个视图实现分页:

我想通过将UIScrollView放入页面并在每个页面中使用新内容更新来修改此内容:

-(void)addContent:(NSString*)txt{

    int size  = 5;
    UITextView *txtView;
    int row = 0;

    //from left
    int xPlace = 0;
    //space between row's
    int rowSpace = 20;
    //from top
    int yPlace = 10;

   // int button_with = scrollView.frame.size.width;
    int button_height = 20;

    for (int i = 0; i < size; i++) {


        txtView = [[UITextView alloc] initWithFrame:CGRectMake(xPlace, row*rowSpace+yPlace, scrollView.frame.size.width, 2*button_height)];
        [txtView setFont:[UIFont fontWithName:@"ArialMT" size:14]];
        txtView.backgroundColor = [UIColor blueColor];

        [txtView setText:[NSString stringWithFormat:@"Numer    %@ - %i",txt,i]];

        // answerCheck.titleLabel.font = [UIFont boldSystemFontOfSize:fontSize];


        [scrollView addSubview:txtView];
        [txtView release];
        row++;
    }

    [scrollView setContentSize:CGSizeMake(scrollView.frame.size.width, txtView.frame.size.height*size)];
}
-(void)addContent:(NSString*)txt{
int size=5;
UITextView*txtView;
int行=0;
//从左
int-xPlace=0;
//行之间的间距
int行空间=20;
//自上而下
int yPlace=10;
//int按钮_with=scrollView.frame.size.width;
int按钮高度=20;
对于(int i=0;i
其想法是,滚动时,只需使用新内容替换uiviewcontroller。它呼吁:

- (void)setPageIndex:(NSInteger)newPageIndex
{
    pageIndex = newPageIndex;

    if (pageIndex >= 0 && pageIndex < [[DataSource sharedDataSource] numDataPages])
    {
        NSDictionary *pageData =
            [[DataSource sharedDataSource] dataForPage:pageIndex];
        label.text = @"Tekstas";//[pageData objectForKey:@"pageName"];
        textView.text = [pageData objectForKey:@"pageText"];
        [self addContent:[pageData objectForKey:@"pageText"]];
        CGRect absoluteRect = [self.view.window
            convertRect:textView.bounds
            fromView:textView];
        if (!self.view.window ||
            !CGRectIntersectsRect(
                CGRectInset(absoluteRect, TEXT_VIEW_PADDING, TEXT_VIEW_PADDING),
                [self.view.window bounds]))
        {
            textViewNeedsUpdate = YES;
        }
    }
} 
-(void)setPageIndex:(NSInteger)newPageIndex
{
pageIndex=newPageIndex;
如果(pageIndex>=0&&pageIndex<[[DataSource sharedDataSource]numDataPages])
{
NSDictionary*页面数据=
[[DataSource sharedDataSource]dataForPage:pageIndex];
label.text=@“Tekstas”;/[pageData objectForKey:@“pageName”];
textView.text=[pageData objectForKey:@“pageText”];
[自添加内容:[pageData objectForKey:@“pageText”];
CGRect absoluteRect=[self.view.window
convertRect:textView.bounds
fromView:textView];
如果(!self.view.window||
!cGRECT交叉点报告(
CGRectInset(绝对直接、文本视图填充、文本视图填充),
[self.view.window边界])
{
textViewNeedsUpdate=是;
}
}
} 
我被困在这里了。我的文本视图正在更新,但UIscrollView的新内容不会在iPad模拟器中更新

是的,我的意思是在iphone上它可以工作,而在iPad上则不行。如果我想实现此功能,我可以改进什么

也许还有其他方法可以从iOS5进行分页

我会把a试图使之发挥作用的消息来源


您只需使用
nib
文件添加一个
UIScrollView
,并固定
width
height
。现在将一些页面制作成
UIView
,并将它们添加到
UIScrollView
,具有相同的大小和相同的
origin
。在主
ui视图中

- (void)viewDidLoad
{
    [super viewDidLoad];

    scrollView.contentSize = CGSizeMake(scrollView.frame.size.width, scrollView.frame.size.height * 2);
}

-(void)viewWillAppear:(BOOL)animated{
    CGFloat h = scrollView.frame.size.height;
    [pageView1 setFrame:CGRectMake(0, 0, pageView1.frame.size.width, pageView1.frame.size.height)];

    [pageView2 setFrame:CGRectMake(0, h, pageView2.frame.size.width, pageView2.frame.size.height)];
}
并且不要忘记在
nib
文件的
属性中检查
分页启用的
UIScrollView


我希望对你有用

对不起,我假设你的滚动是水平的!