2012-04-23 49 views
0

我有5個節的表格視圖,每個節只包含1行,每行顯示一個自定義單元格。一切工作正常,但第零部分重複在第四節,我無法追查這一點。這是我的代碼。UITableView iOS

-(void) setUpActivityView { 
    [self createViews]; 
} 


#pragma mark Table View methods 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 5; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return 1; 
} 


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 

    if (indexPath.section == 0) { 
     return 167; 
    } 
    else if (indexPath.section == 1) { 
     return 200; 
    } 
    else if (indexPath.section == 2) { 
     return 115; 
    } 
    else if (indexPath.section == 3) { 
     return 90; 
    } 
    else { 
     return 155; 
    } 

} 


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"customCellIdentifier"; 

    if (indexPath.section == 0 && indexPath.row == 0) { 
     _notificationCell = (NotificationsCustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

     if (_notificationCell == nil) { 
      _notificationCell = [[[NotificationsCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 

     } 

     _notificationCell.selectionStyle = UITableViewCellSelectionStyleNone; 

     return _notificationCell; 
    } 
    else if (indexPath.section == 1 && indexPath.row == 0) { 
     _topMatchCell = (TopMatchCustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

     if (_topMatchCell == nil) { 
      _topMatchCell = [[[TopMatchCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
     } 

     _topMatchCell.selectionStyle = UITableViewCellSelectionStyleNone; 

     return _topMatchCell; 
    } 
    else if (indexPath.section == 2 && indexPath.row == 0) { 
     _recentlyViewedCell = (RecentlyViewedHomesCustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

     if (_recentlyViewedCell == nil) { 
      _recentlyViewedCell = [[[RecentlyViewedHomesCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
     } 

     _recentlyViewedCell.selectionStyle = UITableViewCellSelectionStyleNone; 

     return _recentlyViewedCell; 
    } else if (indexPath.section == 3 && indexPath.row == 0) { 
     _feedbackCell = (FeedbackCustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

     if (_feedbackCell == nil) { 
      _feedbackCell = [[[FeedbackCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
     } 

     _feedbackCell.selectionStyle = UITableViewCellSelectionStyleNone; 

     return _feedbackCell; 
    } 
    else { 
     _activityTimeLineCell = (ActivityTimeLineCustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

     if (_activityTimeLineCell == nil) { 
      _activityTimeLineCell = [[[ActivityTimeLineCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
     } 

     _activityTimeLineCell.selectionStyle = UITableViewCellSelectionStyleNone; 

     return _activityTimeLineCell; 
    } 
} 


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

} 


- (void)initializeSubViews { 
    _mainTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 412) style:UITableViewStylePlain]; 
} 


- (void)configureLayoutOfSubViews { 
    self._mainTableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Home_Setup1-bg.png"]]; 
// UIColor *lSeperatorColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"line_bg.png"]]; 
// [self._mainTableView setSeparatorColor:lSeperatorColor]; 
} 


- (void)setStylesForSubViews { 
    _mainTableView.separatorStyle = UITableViewCellSeparatorStyleNone; 
    _mainTableView.showsVerticalScrollIndicator = NO; 
    _mainTableView.scrollsToTop = NO; 
} 

- (void)setStateForSubViews { 

} 

- (void)registerTargets { 
    _mainTableView.delegate = self; 
    _mainTableView.dataSource = self; 
} 

-(void)addToParentsView { 
    [self addSubview:_mainTableView]; 
} 

-(void) createViews { 
    [self initializeSubViews]; 
    [self configureLayoutOfSubViews]; 
    [self setStylesForSubViews]; 
    [self setStateForSubViews]; 
    [self registerTargets]; 
    [self addToParentsView]; 
} 

回答

0

對不同的單元使用不同的單元標識符。當新的單元格滾動到您的視圖中時,滾動出視圖的舊單元格將根據您在出列時提供的標識符重用。

讓我猜測,在加載你的第五個細胞不在你的視野內?

+0

是的,我的第五個單元格不在視野中,我將通過具有不同的單元格標識符來檢查。 – 2012-04-23 16:20:40

+0

感謝它的工作。 – 2012-04-23 16:25:53