仿京東金融的理財表(tableview+scrollview嵌套結(jié)構(gòu))

直接上代碼:(封裝性查,只提供一個思路)

1:創(chuàng)建兩個tableview 和 一個scrollview?

2: scrollview 控制 左右滑動,兩個tableview通過代理實現(xiàn)聯(lián)動;

3:限制scrollview的bounce并通過代理控制兩個tableview邊線的顯示;

@interface ViewController ()@property (nonatomic,retain)UIScrollView * scrollview;

@property (nonatomic,retain)UITableView * tableview;

@property (nonatomic,retain)UITableView * tableview2;

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

_scrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(100, 0, self.view.frame.size.width, self.view.frame.size.height)];

[self.view addSubview:_scrollview];

self.scrollview.bounces = NO;

self.scrollview.backgroundColor = [UIColor greenColor];

self.scrollview.contentSize = CGSizeMake(self.view.frame.size.width*2, self.view.frame.size.height);

_tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width-100, self.view.frame.size.height) style:UITableViewStylePlain];

[self.scrollview addSubview:self.tableview];

_tableview.delegate = self;

_tableview.dataSource = self;

[_tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"dddID"];

_tableview.tableFooterView = [[UIView alloc]init];

_tableview2 = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 100, self.view.frame.size.height) style:UITableViewStylePlain];

[self.view addSubview:self.tableview2];

_tableview2.tableFooterView = [[UIView alloc]init];

[_tableview2 registerClass:[UITableViewCell class] forCellReuseIdentifier:@"dddIDs"];

_tableview2.delegate = self;

_tableview2.dataSource = self;

// Do any additional setup after loading the view, typically from a nib.

}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

{

if (scrollView == self.tableview2) {

self.tableview.contentOffset = self.tableview2.contentOffset;

}

else

{

self.tableview2.contentOffset = self.tableview.contentOffset;

}

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

if (tableView == self.tableview2)

{

UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"dddIDs" forIndexPath:indexPath];

cell.textLabel.text = @"sdfsdfdsf";

return cell ;

}

else

{

UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"dddID" forIndexPath:indexPath];

cell.textLabel.text = @"sdfs塌dfdsf";

return cell ;

}

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

if (tableView == self.tableview2)

{

return 6;

}

else

{

return 6;

}

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

if (tableView == self.tableview2) {

return 5;

}

else

{

return 5;

}

}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

{

UILabel * label = [[UILabel alloc]init];

label.text = [NSString stringWithFormat:@"%lu",section];

label.backgroundColor = [UIColor redColor];

return label;

}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

{

return 20;

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容