tableView: cellForRowAtIndexPath: возвращает только одну пользовательскую ячейку uitableview - PullRequest
2 голосов
/ 09 мая 2011

Я прошел через мой отладчик и заметил, что мой код будет возвращать только одну пользовательскую ячейку из моего tableView: cellForRowAtIndexPath: метод. Я не знаю почему или как заставить его вернуть оба пользовательских элемента, которые я хочу ... все этоДоза отображает одну и ту же ячейку в обоих разделах.

    - (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 Ответ

2 голосов
/ 09 мая 2011

попробуйте это

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

            if(indexPath.section==0)
       {............
          return cell;
         }
          else if(indexpath.section==1)
      {
          .....
         return cellbutton;
       }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...