问题描述
UIScrollView
水平滚动,而 UITableView
在内部滚动垂直,但是在水平滚动时无法加载其他数据.
UIScrollView
scrolls Horizontally and UITableView
scrolls vertically inside that but unable to load different data when scroll horizontally.
具有一个可在屏幕上水平滚动的滚动视图,并且在其中已添加了多个tableview,并且希望在滑动时在tableview上显示不同的不同数据.我试过了但是没有运气:(
have one scrollview which scrolls horizontally on screen and inside of that i have added multiple tableview and want to display different different datas on tableview when swipe. i have tried this but with no luck :(
NSArray *arr1 = [[NSArray alloc] initWithObjects:@"1",@"2",@"3", nil];
NSArray *arr2 = [[NSArray alloc] initWithObjects:@"4",@"5",@"6", nil];
NSArray *arr3 = [[NSArray alloc] initWithObjects:@"7",@"8",@"9", nil];
NSArray *arr4 = [[NSArray alloc] initWithObjects:@"10",@"11",@"12", nil];
arrData = [[NSMutableArray alloc] initWithObjects:arr1,arr2,arr3,arr4, nil];
int width=0;
for (int i = 0; i<[arrData count]; i++) {
tblData = [[UITableView alloc] initWithFrame:CGRectMake(width, 20, 300, 245) style:UITableViewStylePlain];
tblData.dataSource = self;
tblData.delegate = self;
[tblData setBackgroundColor:[UIColor clearColor]];
tblData.separatorColor = [UIColor blackColor];
[scrHorizontal addSubview:tblData];
width+=300;
}
[self.scrHorizontal setContentSize:CGSizeMake(([arrData count])*300, self.scrHorizontal.frame.size.height)];
在这里,滚动视图中有4个页面,其中包括4个表视图,我想在滑动滚动视图时在第一张表上显示1,2,3,在第二张表上显示4,5,6 ...
here 4 pages inside scrollview which includes 4 tableviews i want to display 1,2,3 on first table and 4,5,6 on second table when swipe scrollview and so on...
请提前帮助我.
推荐答案
我已经看到了您的代码,可以使用 tag
,
I have seen your code , you can do with tag
,
-
将标记设置为循环使用tableview
set tag to tableview in loop
for (int i = 0; i<[arrData count]; i++) {
tblData = [[UITableView alloc] initWithFrame:CGRectMake(width, 20, 300, 245) style:UITableViewStylePlain];
tblData.tag=i;
tblData.dataSource = self;
tblData.delegate = self;
[tblData setBackgroundColor:[UIColor clearColor]];
tblData.separatorColor = [UIColor blackColor];
[scrHorizontal addSubview:tblData];
width+=300;
}
现在使用 cellForRowAtIndexPath 方法即可喜欢
NSArray *arr = [arrData objectAtIndex:tableView.tag];
cell.textLabel.text = [arr objectAtIndex:indexPath.row];
希望有帮助.
这篇关于iOS-具有多个UITableViews的水平UIScrollView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!