创建一个tableview,让他在view出现后开始滑动,如果设置的偏移量大于这个tableview的高度时,会出现滑动断层的现象。
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (strong , nonatomic) UITableView * tableView;
@end
@implementation ViewController
(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = [UIColor redColor];
UITableView * tableView = [[UITableView alloc]initWithFrame:CGRectMake(100, 200, 200, 300)style:UITableViewStylePlain];
tableView.delegate = self;
tableView.dataSource = self;
self.tableView = tableView;
[self.view addSubview:self.tableView];
}
(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[UIView animateWithDuration:5.0f animations:^{
[self.tableView setContentOffset:CGPointMake(0, 300) animated:NO];
// [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:19 inSection:0] atScrollPosition:UITableViewScrollPositionNone animated:NO];
}];
}
(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 20;
}
(UITableViewCell )tableView:(UITableView )tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString * identifier = @"identifier";
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
cell.textLabel.text = [NSString stringWithFormat:@" %ldcell",indexPath.row];
NSLog(@"*******************%ld cell",indexPath.row);
return cell;
}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...