Кто-нибудь знает, как создать табличное представление, которое состоит из различных типов клеток - PullRequest
4 голосов
/ 02 июня 2010

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

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

функция.

Ответы [ 2 ]

3 голосов
/ 02 июня 2010

Все, что вам нужно сделать, это включить строку или раздел вашего nsindexpath и вернуть соответствующую ячейку UITableView ... допустим, у вас есть TableViewCellA и TableViewCellB один для строки 0, а другой для строки 1

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
     UITableViewCell *cell;
    if(indexPath.row==0)
   {
     cell=..//tableviewcellA 
   }
   if(indexPath.row==1)
    cel=///tableviewcell b 
}

и так далее, надеюсь, это поможет

1 голос
/ 08 июня 2015
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

{ 

NSString *identifier=@"MyCell";

if (indexpath.section==0)

{
 customCell1 *cell1=(customCell1 *)[tableView dequeueReusableCellWithIdentifier:identifier];

    if (cell1==nil)
    {
        NSArray *nib=[[NSBundle mainBundle]loadNibNamed:@"customCell1" owner:self options:nil];
        cell1=[nib objectAtIndex:0];
    }
return cell1;

}

if (indexpath.section==1)

{
 customCell2 *cell2=(customCell2 *)[tableView dequeueReusableCellWithIdentifier:identifier];

    if (cell2==nil)

{
        NSArray *nib=[[NSBundle mainBundle]loadNibNamed:@"customCell2" owner:self options:nil];
        cell2=[nib objectAtIndex:0];
    }
return cell2;

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