Отображение двух разделов определенного размера в табличном представлении - PullRequest
0 голосов
/ 15 ноября 2011

Я пытаюсь заполнить табличное представление массивом, но я хочу два раздела, и в первом разделе я хочу отобразить информацию от indexpath.row == 0 до indexpath.row == 4, а во втором разделе информацию от indexpath.row == 5 до indexpath.row == 9. Как я могу это сделать? У меня есть этот код для второго раздела:

 if (indexPath.section == 1){
        static NSString *CellIdentifier = @"LazyTableCell";
        static NSString *PlaceholderCellIdentifier = @"PlaceholderCell";
        int nodeCount = [self.entries count];
        UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
                                       reuseIdentifier:CellIdentifier] autorelease];
        if (nodeCount > 0)
        {
            if (indexPath.row > 4) {

                AppRecord *appRecord = [self.entries objectAtIndex:indexPath.row];
                cell.textLabel.text = appRecord.artist;
                cell.detailTextLabel.text = appRecord.appName;
                if (!appRecord.appIcon)
                {
                    if (self.tableView.dragging == NO && self.tableView.decelerating == NO)
                    {
                        [self startIconDownload:appRecord forIndexPath:indexPath];
                    }
                    cell.imageView.image = [UIImage imageNamed:@"Placeholder.png"];               
                }
                else
                {
                    UIImage *image = appRecord.appIcon;
                    CGSize itemSize = CGSizeMake(83.0, 48.0);
                    UIGraphicsBeginImageContext(itemSize);
                    CGRect imageRect = CGRectMake(0.0, 0.0, 83.0, 48.0);
                    [image drawInRect:imageRect];
                    appRecord.appIcon = UIGraphicsGetImageFromCurrentImageContext();
                    UIGraphicsEndImageContext();
                    cell.imageView.image = appRecord.appIcon;    
                }


        }
        return cell;  
    }
}

1 Ответ

1 голос
/ 15 ноября 2011

установить номер секции в этой функции

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

Возможно, вы также захотите реализовать

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return @"section title";
}

установить количество строк в следующей функции

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
   return 5; // since you have 0-4 and 5-9 for the two sections
}

после просмотра в вашем коде [self.entries objectAtIndex: indexPath.row];Я предположил, что self.entries - это тот массив, о котором вы говорили.Вы можете инициализировать свойство UITableViewCell в

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

, используя комбинацию раздела и строки для получения индекса ваших self.entries, вероятно, что-то вроде

AppRecord *appRecord = [self.entries objectAtIndex:indexPath.row+5*indexPath.section];

Надеюсь, я получилВаш вопрос правильный.

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