как вернуть два пользовательских uitableviewcells - PullRequest
2 голосов
/ 09 мая 2011

Привет, просто пытаюсь выяснить, как загрузить два разных пользовательских uitableviewcells в два разных раздела моего uitableview ... Просто не уверен, как действовать ... вот код, который у меня сейчас

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

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

- (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];
    }
    return cell;

}

/////// НОВАЯ ПОПЫТКА .... :( если бы можно было так назвать ..

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

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

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

    if (indexPath.section == 0) 
    {
        //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];
        }
        return cell;        

    }
    else if (indexPath.section == 1)
    {
        //Registration Button
        static NSString *CellButtonIdentifier = @"CustomButtonCell";
        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];
        }
        return cellButton;      

    }
    return nil;

}

1 Ответ

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

Используйте свойство section переменной indexPath:

if (indexPath.section == 0) 
{
    // do this
}
else if (indexPath.section == 1)
{
    // do that
}

Номер раздела основан на порядке их появления. Первый раздел, который вы хотите отобразить в tableView, будет 0 и т. Д.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...