iphone code - использовать пользовательскую таблицу вместо таблицы по умолчанию - PullRequest
0 голосов
/ 05 января 2010

Я использую таблицу стилей по умолчанию,
я хочу добавить больше строк в таблицу, как я могу настроить его?

код:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
                                   reuseIdentifier:CellIdentifier] autorelease];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
}

// Leave cells empty if there's no data yet
if (nodeCount > 0)
{
    // Set up the cell...
    ARecord *aRecord = [self.entries objectAtIndex:indexPath.row];

    cell.textLabel.text = aRecord.lDate;
    cell.detailTextLabel.text = aRecord.WNum;

    // Only load cached images; defer new downloads until scrolling ends
    //(!aRecord.appIcon) - use icon
    if (!aRecord.appIcon)
    {
        if (self.tableView.dragging == NO && self.tableView.decelerating == NO)
        {
            [self startIconDownload:aRecord forIndexPath:indexPath];
        }
        // if a download is deferred or in progress, return a placeholder image
        cell.imageView.image = [UIImage imageNamed:@"Placeholder.png"];                
    }
    else
    {
        cell.imageView.image = aRecord.appIcon;
    }

}

return cell;

}

Ответы [ 3 ]

1 голос
/ 05 января 2010

Не уверен, что понимаю вопрос. Количество секций и строк в таблице контролируется табличным представлением UITableViewDataSource (в большинстве примеров кода этот протокол реализуется контроллером представления, но это может быть отдельный объект).

Код, который вы опубликовали, вступает в действие намного позже в процессе: после того, как представление определило, сколько строк присутствует, общее количество, и которые в настоящее время отображаются на экране, и им необходимо отобразить эти строки. Но, как правило, он и другие методы протокола UITableViewDelegate позволяют настроить внешний вид и поведение таблицы. (Наряду со свойствами самого представления.)

1 голос
/ 05 января 2010

Количество строк в табличном представлении определяется тем, что вы возвращаете в

- (NSInteger) tableView: (UITableView *) tableView numberOfRowsInSection: (NSInteger) раздел

если вы вернете 500, у вас будет таблица из 500 строк.

0 голосов
/ 05 января 2010

- (NSInteger) numberOfSectionsInTableView: (UITableView *) tableView { возврат 1; }

- (NSInteger) tableView: (UITableView *) tableView numberOfRowsInSection: (NSInteger) раздел { return [количество табличных массивов]; }

- (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath { NSString * CellIdentifer = [NSString stringWithFormat: @ "% i", indexPath.row]; UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifer]; если (ячейка == ноль) { cell = [self myCustomCell: CellIdentifer dicToSet: [tblArray objectAtIndex: indexPath.row]]; [cell setAccessoryType: UITableViewCellAccessoryDisclosureIndicator]; } возвратная ячейка; }

- (UITableViewCell *) myCustomCell: (NSString *) CellIdentifer dicToSet: (NSDictionary *) dicToSet { UITableViewCell * cell = [[[UITableViewCell alloc] initWithFrame: CGRectMake (0, 0, 320, 44).

UIImageView *imgV=[[UIImageView alloc] initWithFrame:CGRectMake(2, 2, 40, 40)];
[imgV setImage:[UIImage imageNamed:[dicToSet valueForKey:@"Photo"]]];
[cell addSubview:imgV];
[imgV release];




return cell;

}

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