我在xib文件中有兩個tableviewcell,我使用它們兩個。內存warrning tableviewcell
當我使用其中一個內存仍然是7.3MB,但是當我使用這兩個內存增長非常快。
請幫幫我。我現在不是什麼錯。
我的代碼如下:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSUInteger row = [indexPath row];
NSDictionary *rowData = [self.events objectAtIndex:row];
static NSString *CellIdentifierL = @"LeftCell";
static NSString *CellIdentifierR = @"RightCell";
SampleTableCell *cellLeft = [tableView dequeueReusableCellWithIdentifier:CellIdentifierL];
SampleTableCell *cellRight = [tableView dequeueReusableCellWithIdentifier:CellIdentifierR];
if (cellLeft == nil) {
NSArray* topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"LeftTableCell" owner:self options:nil];
for (id currentObject in topLevelObjects) {
if ([currentObject isKindOfClass:[SampleTableCell class]]) {
cellLeft = (SampleTableCell *)currentObject;
break;
}
}
}
if (cellRight == nil) {
NSArray* topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"RightTableCell" owner:self options:nil];
for (id currentObject in topLevelObjects) {
if ([currentObject isKindOfClass:[SampleTableCell class]]) {
cellRight = (SampleTableCell *)currentObject;
break;
}
}
}
return (row%2==0)?cellRight:cellLeft;
}
你有沒有檢查你的內存崩潰報告或intrument日誌,因爲你的代碼看起來很好,你在做什麼與細胞有一些你已離開我猜 – Retro
我看到這段代碼沒有問題。內存佔用量何時增長?滾動表格視圖時? –
兩個理論:1-你確定你的'SampleTableCell'有正確的reusableCellIdentifier嗎? (檢查你的xib)如果沒有,這意味着你正在創造太多的行。 2-你應該確定在創建它們之前你必須創建哪個單元格。儘管如此,這隻對第一個細胞的創造很重要。 –