2011-05-09 33 views
2

我已經通過我的調試器,發現我的代碼將只從我的 的tableView返回一個customcell:的cellForRowAtIndexPath:方法。我不知道爲什麼或如何使它同時返回我想要的customcells ..所有它的劑量是顯示兩個部分中相同的自定義單元格。的tableView:的cellForRowAtIndexPath:只返回一個自定義的UITableViewCell

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 2; 
} 

// Customize the number of rows in the table view. 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    NSInteger rows = 0; 
    switch (section) { 
     case 0: 
      rows = 1; 
      break; 
     case 1: 
      rows = 1; 
      break; 
    } 
    return rows; 
} 


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

     //Registration Button 
     static NSString *CellIdentifier = @"CustomRegCell"; 
     static NSString *CellNib = @"LogInCustomCell"; 

     UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if (cell == nil) { 
      NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CellNib owner:self options:nil]; 
      cell = (UITableViewCell *)[nib objectAtIndex:0]; 
     } 

    //Registration Button 
    static NSString *CellButtonIdentifier = @"CustomSubmitCell"; 
    static NSString *CellButtonNib = @"LogInCustomCell"; 

    UITableViewCell *cellButton = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellButtonIdentifier]; 
    if (cellButton == nil) { 
     NSArray *nibButton = [[NSBundle mainBundle] loadNibNamed:CellButtonNib owner:self options:nil]; 
     cellButton = (UITableViewCell *)[nibButton objectAtIndex:0]; 
    } 
    NSLog(@"%i", indexPath.section); 
    if (indexPath.section == 0) { 
      return cell; // jumps out of method here  

    } 
    if (indexPath.section == 1) { 
     return cellButton;   

    } 
    return nil; 
} 

回答

2

試試這個

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

      if(indexPath.section==0) 
     {............ 
      return cell; 
     } 
      else if(indexpath.section==1) 
     { 
      ..... 
     return cellbutton; 
     } 
} 
+2

好吧,我的繼承人答案測試一個想法,我有以後。 基本上我的代碼是正確的,我的錯誤有事情做,試圖調用兩個定製單元來自同一個.nib文件。自那時以來,我爲自定義提交按鈕創建了一個新的.nib,並將其完美加載到第二個字段中。 所以這是我在界面生成器中進行的設置,有沒有其他人遇到過這個? – tinhead 2011-05-09 05:11:04

相關問題