首页 > 学院 > 开发设计 > 正文

IOS开发基础知识--碎片23

2019-11-14 18:11:51
字体:
来源:转载
供稿:网友

1:关于UITableView中关于行重复加载的问题

  在Cell里重写PRepareForReuse,对一些控件进行清空;

比较简单:-(void)prepareForReuse{    [super prepareForReuse];    _content_label.text = nil;    _time_date_label.text = nil;    _name_label.text = nil;    _career_label.text = nil;}下面这个是我在cell加载一个自定议的视图BLSPrincipalItemView

-(void)prepareForReuse

{

    [super prepareForReuse];

    self.titleLabel.text = nil;

    for (UIView *view in [self.contentView subviews])

    {

        if ([view isKindOfClass:[BLSPrincipalItemView class]])

        {

            [view removeFromSuperview];

        }

    }

}

注意self.contentView,否则在IOS7会没有效果,还是重复的增加跟图片错乱

这边有一段对它进行一个详细的说明:

cell被重用如何提前知道? 重写cell的prepareForReuse官方头文件中有说明.当前已经被分配的cell如果被重用了(通常是滚动出屏幕外了),会调用cell的prepareForReuse通知cell.注意这里重写方法的时候,注意一定要调用父类方法[super prepareForReuse] .这个在使用cell作为网络访问的代理容器时尤其要注意,需要在这里通知取消掉前一次网络请求.不要再给这个cell发数据了.- (void)prepareForReuse{    [super prepareForReuse];}自定义UITableViewCell的方法有很多 发现一些人都会遇到自己定义的cell里面图片错乱的问题 这个问题往往是因为没有实现prepareForReuse这个方法导致的.UITableViewCell在向下滚动时复用, 得用的cell就是滑出去的那些, 而滑出去的cell里显示的信息就在这里出现了 解决的方法就是在UITableViewCell的子类里实现perpareForReuse方法, 把内容清空掉

 2:查看虚拟器的路径

    NSString *path = NSHomeDirectory();//主目录    NSLog(@"NSHomeDirectory:%@",path);

 3:ios8 模拟器路径

IOS 8.0 之前的路径如下:/Users/TESTUSER/Library/application Support/iPhone SimulatoriOS 8.0 后的路径如下:/Users/TESTUSER/Library/Developer/CoreSimulator/Devices/8978B626-387E-40AF-AE99-6DEE931C5FA4/data/Containers/Data/Application

4:CocoaLumberjack日志文件生成的位置

/Users/TESTUSER/Library/Developer/CoreSimulator/Devices/8978B626-387E-40AF-AE99-6DEE931C5FA4/data/Containers/Data/Application/7CA2354E-5B3A-47E2-8F69-A59764538FA1/Library/Caches/Logs/

5:webView加载新闻的URL

    self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0.0, 0.0, ScreenWidth, ScreenHeight)];    self.webView.delegate = self;    NSURL *url = [NSURL URLWithString:self.urlStr];    NSURLRequest *request = [NSURLRequest requestWithURL:url];    [self.webView loadRequest:request];       [self.view addSubview:self.webView];

6:多手指多点击响应

- (void)viewDidLoad {    [super viewDidLoad];        UITapGestureRecognizer *myFingersTwoTaps =    [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(FingersTaps)];    [myFingersTwoTaps setNumberOfTapsRequired:4];    [myFingersTwoTaps setNumberOfTouchesRequired:2];    [[self view] addGestureRecognizer:myFingersTwoTaps];}- (void)FingersTaps {    NSLog(@"Action: 两个手指  连续点击四下");}

7:添加pch文件的步聚

1:创建新文件 ios->other->PCH file,创建一个pch文件:“工程名-Prefix.pch”:2:将building setting中的precompile header选项的路径添加“$(SRCROOT)/项目名称/pch文件名”(例如:$(SRCROOT)/LotteryFive/LotteryFive-Prefix.pch)3:将Precompile Prefix Header为YES,预编译后的pch文件会被缓存起来,可以提高编译速度

 8:隐藏状态栏跟导航栏

viewWillAppear表示视图将呈现出来前-(void)viewWillAppear:(BOOL)animated{    [super viewWillAppear:animated];    [self.navigationController.navigationBar setTranslucent:YES];    [self.navigationController setNavigationBarHidden:YES];}

 9:修改表格行默认分隔线存空隙的问题

    if (!_myTableView) {        _myTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];        _myTableView.backgroundColor = [UIColor clearColor];        _myTableView.showsVerticalScrollIndicator = NO;        _myTableView.showsHorizontalScrollIndicator=NO;                _myTableView.tableFooterView=[[UIView alloc]init];        _myTableView.dataSource = self;        _myTableView.delegate = self;        [_myTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:BLSMaterialDocumentsViewController_CellIdentifier];        [self.view addSubview:_myTableView];                if ([self.myTableView respondsToSelector:@selector(setLayoutMargins:)]) {            self.myTableView.layoutMargins=UIEdgeInsetsZero;        }        if ([self.myTableView respondsToSelector:@selector(setSeparatorInset:)]) {            self.myTableView.separatorInset=UIEdgeInsetsZero;        }    }
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    leftTableCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([leftTableCell class]) forIndexPath:indexPath];    cell.curLeftTagModel = [self.dataList objectAtIndex:indexPath.section];    cell.hasBeenSelected = (cell.curLeftTagModel==self.curSelectModel);            //修改表格行默认分隔线存空隙的问题    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {        cell.layoutMargins=UIEdgeInsetsZero;    }    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {        cell.separatorInset=UIEdgeInsetsZero;    }        return cell;}

 


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表