2013-07-20 53 views
1

下面顯示的是我用來創建單元的代碼。該單元格未被重用。每當cell==nil成爲現實時。UITableViewcell沒有重用

我正在xib中正確設置標識符。請幫幫我。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    SRCourseListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; 

    if (cell == nil) { 

     NSArray *nib=[[NSBundle mainBundle]loadNibNamed:@"SRCourseListCell" owner:self options:nil]; 
     cell=[nib objectAtIndex:0]; 

    } 

    return cell; 
} 

回答

1

在你 「SRCourseListCell.xib」,去屬性檢查器,並設置 「SRCourseListCell」 爲標識符

the Attributes Inspector

更換以下修改後的代碼與您精彩的一個。

 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    SRCourseListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SRCourseListCell"]; 
    if (cell == nil) 
    { 
     NSArray *nib=[[NSBundle mainBundle]loadNibNamed:@"SRCourseListCell" owner:self options:nil]; 
     cell=[nib objectAtIndex:0]; 
    } 
    return cell; 
} 

當調用自定義單元格廈門國際銀行,確保了廈門國際銀行標識符必須是一樣的,你使用的是帶有:

[tableView dequeueReusableCellWithIdentifier:@"SRCourseListCell"]
-1

使用下面的代碼來初始化:

YourTableViewCell *cel = [[YourTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"identifier"];