ios - tableview自动滑动的奇怪现象
高洛峰
高洛峰 2017-04-17 16:09:33
[iOS讨论组]

创建一个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;

    }

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

全部回复(0)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号