zoukankan      html  css  js  c++  java
  • [某鸥实训记][objective-c][第五天][个人笔记]

    TableView+ScrollView

    • 往cell里加label
    • 解决重影的办法
      • 重用cell的时候删除元素

    NSArray *subViews = cell.subviews;

        for (UIView *view in subViews) {

            [view removeFromSuperview];

        }

    • 在if(cell==nil)中去定义子视图,加上tag值.在外边通过tag值获取视图,修改值
    • 封装一个自定义的cell类

    //http://www.tuicool.com/articles/bE7JNnI

    • 将获得cell的方法从- (UITableViewCell*)dequeueReusableCellWithIdentifier:(NSString*)identifier 换为-(UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath.重用机制调用的就是dequeueReusableCellWithIdentifier这个方法,方法的意思就是“出列可重用的cell”,因而只要将它换为cellForRowAtIndexPath(只从要更新的cell的那一行取出cell),就可以不使用重用机制,因而问题就可以得到解决,虽然可能会浪费一些空间。
    • 通过为每个cell指定不同的重用标识符(reuseIdentifier)来解决。重用机制是根据相同的标识符来重用cell的,标识符不同的cell不能彼此重用。于是我们将每个cell的标识符都设置为不同,就可以避免不同cell重用的问题了。

    //http://www.mamicode.com/info-detail-470734.html

    下面是用ScrollView的一段代码

     1 - (void)viewDidLoad {
     2     [super viewDidLoad];
     3     //控制条?不透明
     4     self.navigationController.navigationBar.translucent = NO;
     5     UIScrollView *scroll = [[UIScrollView alloc] init];
     6     scroll.frame = self.view.frame;
     7     scroll.backgroundColor = [UIColor darkGrayColor];
     8     scroll.contentSize = CGSizeMake(self.view.frame.size.width*5, self.view.frame.size.height-64);
     9     NSLog(@"%f",(double) self.navigationController.navigationBar.frame.size.height);
    10     //一页一页的滑动
    11     scroll.pagingEnabled = YES;
    12     scroll.contentOffset = CGPointMake(self.view.frame.size.width*2,0);
    13     [self.view addSubview:scroll];
    14     
    15     for (int i=0;i<5; i++) {
    16         UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(image)];
    17         UIImageView *imageView = [[UIImageView alloc] init];
    18         imageView.userInteractionEnabled = YES;
    19         imageView.frame = CGRectMake(self.view.frame.size.width*i, 0, self.view.frame.size.width, self.view.frame.size.height-64);
    20         NSLog(@"%f",(double) self.navigationController.navigationBar.frame.size.height);
    21         imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"t%d.png",i+1]];
    22         [imageView addGestureRecognizer:tap];
    23         [scroll addSubview:imageView];
    24     }
    25     // Do any additional setup after loading the view, typically from a nib.
    26 }
    27 
    28 - (void)image{
    29     FirstViewController *firstVC = [FirstViewController new];
    30     [self.navigationController pushViewController:firstVC animated:YES];
    31 }
  • 相关阅读:
    【181】IDL 代码从 Windows 转移到 Linux
    异步加载图片到GridView上,防止OOM
    10881
    AngularJS的开发工具---yeoman 简易安装
    AIX操作oracle
    hdu2817 A sequence of numbers
    FZU 2104 (13.11.28)
    HDU 1231 (13.12.2)
    Java 23种设计模式详尽分析与实例解析之一--创建型模式
    JSP视频
  • 原文地址:https://www.cnblogs.com/NyaSu/p/4801933.html
Copyright © 2011-2022 走看看