2017-04-19 98 views
-5
let cell = tableView.dequeueReusableCellWithIdentifier("cellReuseIdentifier", forIndexPath: indexPath) as! CustomTableViewCell 

我不想在创建单元格后重用单元​​格,我希望它在内存中可用。不要在UITableView中重用单元格

+0

的NSArray的你面对什么样的问题? – KKRocks

+0

我不想重用单元格,如果我在添加到单元格的堆栈视图中查看。在隐藏这些子视图时,约束会受到影响,UI会受到干扰。 –

+0

所以我想把细胞留在记忆中。 @KKRocks –

回答

5

这是你的决定当然,但它是一个很糟糕的想法。除非您的tableView中的单元格少于10个,并且您100%确定将不再有单元格。否则,应用程序将很快崩溃内存压力。

只是不要dequeue单元格。每次创建新品:

let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "CellReuseIdentifier") 

不推荐,但这是您的决定毕竟。

+0

我有一个自定义单元类。不能使用上面的代码。 –

+0

@MukulMore然后:'let cell = UITableViewCell(style:UITableViewCellStyle.default,reuseIdentifier:“CellReuseIdentifier”)as! CustomTableViewCell' –

+1

'let cell = YourCustomTableViewCell(style:UITableViewCellStyle.default,reuseIdentifier:“YourCustomCellReuseIdentifier”)as! YourCustomTableViewCell' –

0

如果你限制了细胞的数量则只有您应该使用此方法

在viewDidLoad中(),您可以创建自定义单元格

self.arrMainCell.addObject(your custom cell); 

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return self.arrMain.count 
} 

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

    let cell = self.arrMain.objectAtIndex(indexPath.row) 

}