2012-04-23 6 views
0

5つのセクションを持つテーブルビューを持っています。各セクションには1つの行しか含まれていません。各行にカスタマイズされたセルが表示されます。すべてが正常に機能していますが、セクション4ではセクションゼロが繰り返されていますが、これをトレースすることはできません。これは私のコードです。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

異なるセルに異なるセル識別子を使用します。新しいセルがビューにスクロールすると、ビューからスクロールした古いセルは、デキュー時に指定した識別子に基づいて再利用されます。

あなたの5番目のセルが表示されていない場合は、読み込んでみてください。

+0

はい私の5番目のセルは見えません。別のセル識別子を持つことでチェックします。 –

+0

ありがとうございます。 –

関連する問題