• (iOS)关于UITableView设置contentsize(原创)


    由于UITableView是继承自UIScrollView的,所以他是可以设置contentsize的。

    但是,我在试验的过程中,初始化UITableView实例后,直接设置它的contentsize是不起作用,在搜寻相关资料得知,UITableView会自动设置contentsize,因为我们在建立tableview的时候是不用自己去设置contentsize的,她是自己计算出来的。

     

    高潮要来了!!!

     

    她是在实现她的datasource代理方法之后计算的。

    一下几个方法:

    - (NSInteger)numberOfSections;

    - (NSInteger)numberOfRowsInSection:(NSInteger)section;

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;

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

    - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;

     

    这些是计算她的height的,而width她会默认的设置为tableview的frame的width。so当你的scrollview的contentsize的width和frame的width一样大的时候,她是不会滑动的,所以,为什么,我们费心设置contentsize不起作用了。因为我们之前怎么设置,她都会默认经过那几个方法的时候自动重算一遍。

     

    高潮来了!!!

    那我们如何自己设置她的contentsize呢,我是在

    - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath代理中做的,并且设置成功了。

     

    总结,开始我以为既然tableview是继承自scrollview的,那她为什么不能设置contentsize呢,难道scrollview中有其他限制?或者是tableview中有限制。最后得知了她的自己重算流程,得知原来,她是在进行datasource的时候,重新设置了。

    那最后想到,我们在她自动设置完成后,我们再给她设置一下不就好了。

  • 相关阅读:
    Windows进程/线程创建过程
    固件安全研究
    区块链安全研究的总结
    CoTreatAsClass一些注意事项
    Ring3 读取SSDT
    User Mode Scheduling
    首次异常和二次异常
    offer终于有着落了
    AtomBombing
    Retn
  • 原文地址:https://www.cnblogs.com/hikoming/p/3452223.html
Copyright © 2020-2023  润新知