IOS开发基础知识--碎片23
1:關(guān)于UITableView中關(guān)于行重復(fù)加載的問(wèn)題
? 在Cell里重寫prepareForReuse,對(duì)一些控件進(jìn)行清空;
比較簡(jiǎn)單:-(void)prepareForReuse{[super prepareForReuse];_content_label.text = nil;_time_date_label.text = nil;_name_label.text = nil;_career_label.text = nil; }下面這個(gè)是我在cell加載一個(gè)自定議的視圖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會(huì)沒(méi)有效果,還是重復(fù)的增加跟圖片錯(cuò)亂
這邊有一段對(duì)它進(jìn)行一個(gè)詳細(xì)的說(shuō)明:
cell被重用如何提前知道? 重寫cell的prepareForReuse官方頭文件中有說(shuō)明.當(dāng)前已經(jīng)被分配的cell如果被重用了(通常是滾動(dòng)出屏幕外了),會(huì)調(diào)用cell的prepareForReuse通知cell.注意這里重寫方法的時(shí)候,注意一定要調(diào)用父類方法[super prepareForReuse] .這個(gè)在使用cell作為網(wǎng)絡(luò)訪問(wèn)的代理容器時(shí)尤其要注意,需要在這里通知取消掉前一次網(wǎng)絡(luò)請(qǐng)求.不要再給這個(gè)cell發(fā)數(shù)據(jù)了. - (void)prepareForReuse {[super prepareForReuse]; } 自定義UITableViewCell的方法有很多 發(fā)現(xiàn)一些人都會(huì)遇到自己定義的cell里面圖片錯(cuò)亂的問(wèn)題 這個(gè)問(wèn)題往往是因?yàn)闆](méi)有實(shí)現(xiàn)prepareForReuse這個(gè)方法導(dǎo)致的. UITableViewCell在向下滾動(dòng)時(shí)復(fù)用, 得用的cell就是滑出去的那些, 而滑出去的cell里顯示的信息就在這里出現(xiàn)了 解決的方法就是在UITableViewCell的子類里實(shí)現(xiàn)perpareForReuse方法, 把內(nèi)容清空掉?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/Application4: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:多手指多點(diǎn)擊響應(yīng)
- (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: 兩個(gè)手指 連續(xù)點(diǎn)擊四下"); }7:添加pch文件的步聚
1:創(chuàng)建新文件 ios->other->PCH file,創(chuàng)建一個(gè)pch文件:“工程名-Prefix.pch”: 2:將building setting中的precompile header選項(xiàng)的路徑添加“$(SRCROOT)/項(xiàng)目名稱/pch文件名”(例如:$(SRCROOT)/LotteryFive/LotteryFive-Prefix.pch) 3:將Precompile Prefix Header為YES,預(yù)編譯后的pch文件會(huì)被緩存起來(lái),可以提高編譯速度?8:隱藏狀態(tài)欄跟導(dǎo)航欄
viewWillAppear表示視圖將呈現(xiàn)出來(lái)前-(void)viewWillAppear:(BOOL)animated {[super viewWillAppear:animated];[self.navigationController.navigationBar setTranslucent:YES];[self.navigationController setNavigationBarHidden:YES]; }?9:修改表格行默認(rèn)分隔線存空隙的問(wèn)題
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);//修改表格行默認(rèn)分隔線存空隙的問(wèn)題if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {cell.layoutMargins=UIEdgeInsetsZero;}if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {cell.separatorInset=UIEdgeInsetsZero;}return cell; }?
新人創(chuàng)作打卡挑戰(zhàn)賽發(fā)博客就能抽獎(jiǎng)!定制產(chǎn)品紅包拿不停!總結(jié)
以上是生活随笔為你收集整理的IOS开发基础知识--碎片23的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 高性能JavaScript-JS脚本加载
- 下一篇: 微信开发测试号配置