常規(guī)寫(xiě)法
static NSString *identifier = @"MoneySection";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
cell.textLabel.text = @"需支付金額:¥160.00";
return cell;
分析一下不加static的情況
1、identifier存在棧區(qū),出了最后大括號(hào)}就被棧自動(dòng)回收;這樣每次調(diào)用cellForRowAtIndexPath方法,棧中都要重新生成臨時(shí)變量identifier,并讓其指向常量區(qū)@“MoneySection”, 消耗內(nèi)存;
3、如果加上static,棧中的變量identifier就不會(huì)銷(xiāo)毀,一直指向常量區(qū)的@“MoneySection”,這樣比較合理。