Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.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
Iphone 如何使用PageControl在UIScrollView中添加UITableView_Iphone_Uitableview_Uiscrollview - Fatal编程技术网

Iphone 如何使用PageControl在UIScrollView中添加UITableView

Iphone 如何使用PageControl在UIScrollView中添加UITableView,iphone,uitableview,uiscrollview,Iphone,Uitableview,Uiscrollview,在我的ViewController中,我有两个uitableview。其中一个是静态的,有一个部分和两行,而另一个只有一个部分和四行。 我想用UIPageControl创建一个UIScrollview,并在每个页面中添加第二个包含四行的tableView。但scrollView中的页数可以更改。所以我尝试使用UILabel,但在tableView中我看不到它 我不知道你是否理解我的问题。我把我的循环代码 for (int i = 1; i < [listAllContactDetails

在我的ViewController中,我有两个uitableview。其中一个是静态的,有一个部分和两行,而另一个只有一个部分和四行。 我想用
UIPageControl
创建一个
UIScrollview
,并在每个页面中添加第二个包含四行的tableView。但scrollView中的页数可以更改。所以我尝试使用UILabel,但在tableView中我看不到它

我不知道你是否理解我的问题。我把我的循环代码

for (int i = 1; i < [listAllContactDetails count] + 1; i++) 
 {
        UILabel *nomContact = [[UILabel alloc] initWithFrame:CGRectMake((i-1)*320, 20, 320, 30)];
        nomContact.backgroundColor = [UIColor yellowColor];
        nomContact.text = [[listAllContactDetails objectAtIndex:i-1] valueForKey:@"name"];
        [scroller addSubview:nomContact];
        [nomContact release];
 }

 scroller.delegate = self;
 scroller.contentSize = CGSizeMake(320*[listAllContactDetails count], 249);
 scroller.pagingEnabled = YES;

 pageControl.numberOfPages = [listAllContactDetails count];
 pageControl.currentPage = 0;
for(int i=1;i<[ListalContactDetails计数]+1;i++)
{
UILabel*nomContact=[[UILabel alloc]initWithFrame:CGRectMake((i-1)*320,20,320,30)];
nomContact.backgroundColor=[UIColor yellowColor];
nomContact.text=[[listAllContactDetails对象索引:i-1]valueForKey:@“name”];
[滚动条添加子视图:nomContact];
[接触释放];
}
scroller.delegate=self;
scroller.contentSize=CGSizeMake(320*[ListalContactDetails count],249);
scroller.PaginEnabled=是;
pageControl.numberOfPages=[ListalContactDetails计数];
pageControl.currentPage=0;
此代码与UILabel匹配,但与UITableView不匹配


感谢您的帮助。

您应该能够通过在循环中设置其框架,将UITableView添加到每个页面,就像您对标签所做的一样

问题是连接数据源。您需要将每个表视图的datasource属性绑定到循环中的视图控制器。然后根据循环索引为循环中的每个表指定不同的.tag属性。在datasource方法中,您需要检查tableview的标记以确定它是哪个页面。像这样:

for (int i = 0; i < [listAllContactDetails count]; i++) 
 {
        UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(i*320, 0, 320, 200) style:...]
        tableView.dataSource = self;
        tableView.tag = i + 1;
        [scroller addSubview:tableView];
        [tableView release];
 }

 scroller.delegate = self;
 scroller.contentSize = CGSizeMake(320*[listAllContactDetails count], 249);
 scroller.pagingEnabled = YES;

 pageControl.numberOfPages = [listAllContactDetails count];
 pageControl.currentPage = 0;

这会很好,但我不明白,因为关于rowInSections的数量是有效的,但关于rowInDexPath的高度是无效的。当我更改报税表时,它们没有变化。谢谢你的回答,但是这里有一个小问题:正在创建和填充tableview,但是你不能在tableview中向下滚动。有什么解决办法吗?
 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
 {
        NSInteger tag = tableView.tag;
        switch (tag)
        {
            case 1:
                return numberOfRowsForPage1;
            case 2:
                return numberOfRowsForPage2;
            etc...
        }
 }