запрос на ошибку участника при загрузке в customtableviewcell и настройке его IBOUTLETS - PullRequest
0 голосов
/ 13 мая 2011

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

здесьмой код

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        static NSString *CellIdentifier = @"TableViewCell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

        if (cell == nil) {
            NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"TableViewCell" owner:self options:nil];
        cell = (UITableViewCell *)[nib objectAtIndex:0];


            //cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
        }

        //cell.imageViewSection =

        // Set up the cell
        int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];

        NSString *textTitle = [[stories objectAtIndex: storyIndex] objectForKey: @"title"];

        NSURL *imageurl = [NSURL URLWithString:[[stories objectAtIndex: storyIndex] objectForKey: @"description"]];
        UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:imageurl]];



        cell.imageViewSection = image;
        cell.titleLabelText.text = textTitle;

return cell;

}

Если кто-то может мне помочь, это было бы здорово :) 1006 *

Ответы [ 2 ]

1 голос
/ 13 мая 2011

Не следует полагаться на то, что ячейка всегда возвращается как объект с индексом 0 в массиве.Выполните простой цикл, чтобы найти фактическую ячейку.

И добавьте типы типов для подкласса ячейки, который вы используете

-(UITableViewCell*)tableView:(UITableView*)tableView
       cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
    static NSString* cellID = @"cellID";
    MyCell* cell = (id)[tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"TableViewCell" 
                                                     owner:self 
                                                   options:nil];
        for (cell in nib) {
            if ([cell isKindOfClass:[MyCell class]]) {
                break;
            }
        }
     }
     // Safely do tuff to cell
     return cell;
}

В этом фрагменте предполагается, что ячейка, по крайней мере, доступна, поведение, если таблицы нетвозвращаемая ячейка просмотра не определена.

0 голосов
/ 13 мая 2011

Вы назначаете и преобразуете TableViewCell в переменную UITableViewCell, а UITableViewCell не имеет этих выходов.Вместо этого вы должны сделать следующее ..

TableViewCell *cell = (TableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"TableViewCell" owner:self options:nil];
    cell = (TableViewCell *)[nib objectAtIndex:0];
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...