解決UITableViewCell出現重疊的問題

當然大家大多在使用自定義cell的情況下,會有出現重疊的情況,現在就本人使用的比較方便的解決辦法分享給大家:
一般固定的源代碼:
#import “MyCell.h”
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  static NSString *CellIdentifier = [NSString stringWithFormat:@"Cell"];
  MyCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) { cell = [[[MyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
} return cell;}

解決的方案:
#import “MyCell.h”
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  static NSString *CellIdentifier = [NSString stringWithFormat:@"Cell"];
  MyCell *cell = nil;//這個地方改變了
if (cell == nil) {  
  cell = [[[MyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
  }  
 return cell;
}
我使用過程中一般情況下可以解決問題,如沒有達到您的要求,請繼續查找其他資料。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章