




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
【移動應(yīng)用開發(fā)技術(shù)】iOS中3DTouch預(yù)覽導(dǎo)致TableView滑動卡頓怎么辦
1.發(fā)現(xiàn)問題/upload/information/20200623/126/119526.gif2.排除問題///行高寫死后依舊卡頓
-
(CGFloat)tableView:(UITableView
*)tableView
heightForRowAtIndexPath:(NSIndexPath
*)indexPath
{
//return
[self.tableView
cellHeightForIndexPath:indexPath
model:self.dataArray[indexPath.row]
keyPath:@"model"
cellClass:[JstyleNewsOnePlusImageVideoViewCell
class]
contentViewWidth:kScreenWidth];
return
200;
}-
(UITableViewCell
*)tableView:(UITableView
*)tableView
cellForRowAtIndexPath:(NSIndexPath
*)indexPath
{
//省略部分防崩潰判斷代碼...
JstyleNewsHomePageModel
*model
=
self.dataArray[indexPath.row];
switch
([model.type
integerValue])
{
case
1:{
if
([model.head_type
integerValue]
==
1
&&
[model.isImageArticle
integerValue]
==
1)
{
static
NSString
*ID
=
@"JstyleNewsOnePlusImageArticleViewCell";
/*換一種Cell復(fù)用方法,效果依舊卡頓,證明TableViewCell復(fù)用沒有問題。
JstyleNewsOnePlusImageArticleViewCell
*cell
=
[tableView
dequeueReusableCellWithIdentifier:ID];
if
(!cell)
{
cell
=
[[JstyleNewsOnePlusImageArticleViewCell
alloc]initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:ID];
}
*/
JstyleNewsOnePlusImageArticleViewCell
*cell
=
[tableView
dequeueReusableCellWithIdentifier:ID
forIndexPath:indexPath];
///劇透:卡頓的原因就在這!Cell重復(fù)注冊3DTouch預(yù)覽!后面會說解決辦法。
[self
registerForPreviewingWithDelegate:self
sourceView:cell];
if
(indexPath.row
<
self.dataArray.count)
{
cell.model
=
model;
}
cell.selectionStyle
=
UITableViewCellSelectionStyleNone;
return
cell;
}
//else
if...
//case
2:...
}/upload/information/20200623/126/119527.jpg3.定位問題#pragma
mark
-
3DTouch預(yù)覽
-
(UIViewController
*)previewingContext:(id<UIViewControllerPreviewing>)previewingContext
viewControllerForLocation:(CGPoint)location
{
NSIndexPath
*indexPath
=
[self.tableView
indexPathForCell:(UITableViewCell*
)[previewingContext
sourceView]];
if
([self.dataArray[indexPath.row]
isImageArticle].integerValue
==
1)
{
JstylePictureTextViewController
*pictureVC
=
[[JstylePictureTextViewController
alloc]
init];
if
(indexPath.row
<
self.dataArray.count)
{
pictureVC.rid
=
[self.dataArray[indexPath.row]
id];
CGRect
rect
=
CGRectMake(0,
0,
self.view.frame.size.width,[self.tableView
cellForRowAtIndexPath:indexPath].height);
previewingContext.sourceRect
=
rect;
}
return
pictureVC;
}
else
{
JstyleNewsArticleDetailViewController
*detailVC
=
[[JstyleNewsArticleDetailViewController
alloc]
init];
detailVC.preferredContentSize
=
CGSizeMake(0.0f,500.0f);
if
(indexPath.row
<
self.dataArray.count)
{
detailVC.rid
=
[self.dataArray[indexPath.row]
id];
detailVC.titleModel
=
self.detailDataArray[indexPath.row];
CGRect
rect
=
CGRectMake(0,
0,
self.view.frame.size.width,[self.tableView
cellForRowAtIndexPath:indexPath].height);
previewingContext.sourceRect
=
rect;
}
return
detailVC;
}
}-
(UITableViewCell
*)tableView:(UITableView
*)tableView
cellForRowAtIndexPath:(NSIndexPath
*)indexPath
{
static
NSString
*ID
=
@"JstyleNewsOnePlusImageArticleViewCell";
JstyleNewsOnePlusImageArticleViewCell
*cell
=
[tableView
dequeueReusableCellWithIdentifier:ID];
if
(!cell)
{
cell
=
[[JstyleNewsOnePlusImageArticleViewCell
alloc]initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:ID];
}
//?。?!是他是他就是他?。?!每一次滑動TableView復(fù)用Cell的時候都會注冊一遍3DTouch代理!不卡才怪了!
//[self
registerForPreviewingWithDelegate:self
sourceView:cell];注釋掉之后,瞬間“縱享絲滑”!
if
(indexPath.row
<
self.dataArray.count)
{
cell.model
=
model;
}
cell.selectionStyle
=
UITableViewCellSelectionStyleNone;
return
cell;
}4.解決問題//
//
JstyleNewsBaseTableViewCell.h
//
JstyleNews
//
//
Created
by
王磊
on
2018/1/25.
//
Copyright
©
2018年
JstyleNews.
All
rights
reserved.
//
///抽取一個BaseCell基類,后面的子類Cell只需繼承
#import
<UIKit/UIKit.h>
@interface
JstyleNewsBaseTableViewCell
:
UITableViewCell
///是否設(shè)置過3DTouch代理
@property
(nonatomic,
assign
,
readonly)
BOOL
isAllreadySetupPreviewingDelegate;
/**
給當(dāng)前Cell設(shè)置3DTouch代理,方法內(nèi)部自動判定是否已經(jīng)設(shè)置過.
@param
controller
代理控制器
*/
-
(void)setupPreviewingDelegateWithController:(UIViewController<UIViewControllerPreviewingDelegate>
*)controller;
@end//
//
JstyleNewsBaseTableViewCell.m
//
JstyleNews
//
//
Created
by
王磊
on
2018/1/25.
//
Copyright
©
2018年
JstyleNews.
All
rights
reserved.
//
#import
"JstyleNewsBaseTableViewCell.h"
@interface
JstyleNewsBaseTableViewCell
()
///標(biāo)識當(dāng)前Cell是否注冊過
@property
(nonatomic,
assign)
BOOL
isAllreadySetupPreviewingDelegate;
@end
@implementation
JstyleNewsBaseTableViewCell
-
(void)setupPreviewingDelegateWithController:(UIViewController<UIViewControllerPreviewingDelegate>
*)controller
{
if
(self.isAllreadySetupPreviewingDelegate
==
YES)
{
return;
}
if
([self
respondsToSelector:@selector(traitCollection)])
{
if
([self.traitCollection
respondsToSelector:@selector(forceTouchCapability)])
{
if
(self.traitCollection.forceTouchCapability
==
UIForceTouchCapabilityAvailable)
{
[controller
registerForPreviewingWithDelegate:controller
sourceView:self];
self.isAllreadySetupPreviewingDelegate
=
YES;
}
else
{
self.isAllreadySetupPreviewingDelegate
=
NO;
}
}
}
}
-
(BOOL)isAllreadySetupPreviewingDelegate
{
return
_isAllreadySetupPreviewingDelegate;
}-
(UITableViewCell
*)tableView:(UITableView
*)tableView
cellForRowAtIndexPath:(NSIndexPath
*)indexPath
{
//防崩潰代碼省略...
JstyleNewsHomePageModel
*model
=
self.dataArray[indexPath.row];
switch
([model.type
integerValue])
{
case
1:{
if
([model.head_type
integerValue]
==
1
&&
[model.isImageArticle
integerValue]
==
1)
{
static
NSS
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 供應(yīng)材料解除合同范本
- 化妝合同范本
- 代理雨鞋采購合同范本
- 獸藥委托加工合同范本
- 公租房出售合同范本
- 代理工程合同范本
- 買新房認(rèn)購合同范例
- 2024年洛陽市新安縣龍?zhí)洞髰{谷荊紫仙山景區(qū)招聘考試真題
- 農(nóng)業(yè)技術(shù)人員服務(wù)合同范本
- 2024年菏澤市勞信就業(yè)服務(wù)有限公司招聘制醫(yī)院人員考試真題
- 中國電信行業(yè)人工智能行業(yè)市場調(diào)研及投資規(guī)劃建議報告
- 水幕噴淋系統(tǒng)的工作原理與應(yīng)用
- 門樓施工方案
- 全國職業(yè)院校技能大賽高職組(康復(fù)治療技術(shù)賽項)考試及答案
- 2024年08月河北唐山銀行第二批社會招考筆試歷年參考題庫附帶答案詳解
- 2024年山東海洋集團有限公司社會招聘考試真題
- 《感冒中醫(yī)治療》課件
- 研發(fā)費用管理制度內(nèi)容
- 壓力容器設(shè)計委托書
- 《眉毛的基本技法》課件
- 2025年幼兒園膳食工作計劃
評論
0/150
提交評論