tableView:cellForRowAtIndexPath:只返回一个自定义的uitableviewcell

时间:2011-05-09 04:50:04

标签: iphone ios uitableview

我已经通过我的调试器并注意到我的代码只返回我的一个customcell tableView:cellForRowAtIndexPath:method ..我不知道为什么或如何使它返回我想要的两个自定义单元..它的所有剂量都在两个部分中显示相同的自定义单元格。

    - (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; 
}

1 个答案:

答案 0 :(得分:2)

尝试这个

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

            if(indexPath.section==0)
       {............
          return cell;
         }
          else if(indexpath.section==1)
      {
          .....
         return cellbutton;
       }
}
相关问题