2 różne typy niestandardowych komórek UITableView w UITableView

W moim UITableView chcę ustawić dla pierwszej wiadomości kanału RSS niestandardową tableViewCell (Typ A powiedzmy) i dla innych wiadomości drugi, trzeci itp.. inny niestandardowy tableViewCell(trype B) problem polega na tym, że Niestandardowy tableViewCell (trype a) utworzony dla pierwszej wiadomości jest ponownie używany, ale co ciekawe liczba wierszy między pierwszym użyciem customViewCell (Typ A) a drugim wyglądem tego samego typu customViewCell nie jest równa..

My cellForRowAtIndexPath it looks like to.

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

    int feedIndex = [indexPath indexAtPosition:[indexPath length] - 1];
    Feed *item = [[[[self selectedButton] category] feedsList] objectAtIndex:feedIndex + 1];
    static NSString *CellIdentifier = @"Cell";

    if(feedIndex == 0){
        MainArticleTableViewCell *cell = (MainArticleTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

        if (cell == nil)
        {
            cell = [[[MainArticleTableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
            [[[cell subviews] objectAtIndex:0] setTag:111];
        }

        cell.feed = item;

        return cell;

    }
    else{
        NewsTableViewCell *cell = (NewsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

        if (cell == nil)
        {
            cell = [[[NewsTableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier orientation:currentOrientation] autorelease];
            [[[cell subviews] objectAtIndex:0] setTag:111];
        }

        cell.feed = item;

        return cell;

    }
    return nil;
}    

Oba typy komórek mają różną wysokość, która jest ustawiona poprawnie. czy ktoś mógłby mi wskazać w dobrym kierunku jak sprawić, by typ był komórką niestandardową, która pojawiała się tylko przy pierwszych wiadomościach (nie była ponownie używana)? Dziękuję

Author: Sorin Antohi, 2009-09-10

3 answers

Powinieneś utworzyć inny identyfikator komórki dla dwóch stylów komórki:

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

int feedIndex = [indexPath indexAtPosition:[indexPath length] - 1];
Feed *item = [[[[self selectedButton] category] feedsList] objectAtIndex:feedIndex + 1];

static NSString *CellIdentifier1 = @"Cell1";
static NSString *CellIdentifier2 = @"Cell2";

if(feedIndex == 0) {

   MainArticleTableViewCell *cell = (MainArticleTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier1];

   if (cell == nil) {
       cell = [[[MainArticleTableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier1] autorelease];
       [[[cell subviews] objectAtIndex:0] setTag:111];
   }

   cell.feed = item;

   return cell;
}
else {
   NewsTableViewCell *cell = (NewsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier2];

   if (cell == nil) {
       cell = [[[NewsTableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier2 orientation:currentOrientation] autorelease];
       [[[cell subviews] objectAtIndex:0] setTag:111];
   }

   cell.feed = item;

   return cell;
}

return nil;
}
 78
Author: Philippe Leybaert,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-09-10 14:49:21

Nie do końca rozumiem twoje pytanie, ale zauważyłem dwie ciekawe rzeczy. Jeśli używasz dwóch różnych typów komórek, musisz użyć dwóch różnych identyfikatorów komórek podczas wywoływania 'dequeueReusableCellWithIdentifier'. Obecnie używasz tego samego identyfikatora dla obu, co jest nieprawidłowe. Spróbuj czegoś takiego:

static NSString *MainArticleIdentifier = @"MainArticle";
static NSString *NewsIdentifier = @"News";

Również, nigdy nie widziałem czegoś takiego jak:

int feedIndex = [indexPath indexAtPosition:[indexPath length] - 1];

Dlaczego po prostu nie używać:

int feedIndex = indexPath.row;
 8
Author: Chris Karcher,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-09-10 14:52:42

In cellForRowAtIndexPath

if ("Condition for cell 1") {
        cellV = ("customCell" *)[tableView dequeueReusableCellWithIdentifier:@"your ID cell in .xib"];

        if (cellV == nil) {
            [[NSBundle mainBundle] loadNibNamed:@"YOUR-CELL-FILENAME" owner:self options:nil];
            cellV = "OUTLET-CEll-IN-VC";
        }
    } else {
        cellV = ("customCell" *)[tableView dequeueReusableCellWithIdentifier:@"your ID cell2 in .xib"];

        if (cellV == nil) {
            [[NSBundle mainBundle] loadNibNamed:@"YOUR-CELL2-FILENAME" owner:self options:nil];
            cellV = "OUTLET-CEll-IN-VC";
        }
    }

[self configureCell:cellV indexpath:indexPath withClipVo:clip];

return cellV;
 0
Author: jose920405,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-08-20 20:52:54