ObjectiveC - ошибка при загрузке ячеек таблицы - PullRequest
0 голосов
/ 16 июня 2011

Я написал этот метод в ObjectiveC (для iOS, но это нематериально).Мое приложение падает при вызове этого метода.Я пишу все это в моем .m файле.Не могу выяснить причину аварии ...

-(UITableViewCell *)myCell:(UITableViewCell *)cell 
               forRowIndex:(NSIndexPath *)indexPath
{
    //customize the cell.
    return cell;
}

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellId = @"Cell";
    UITableViewCell *cell   = [tableView dequeueReusableCellWithIdentifier:CellId];
    if(cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ResultsOne" owner:self options:nil];
        cell         = self.resultsOne;
    }
    cell = [self myCell:cell:indexPath]; //code crashes here
    return cell;
}

Что я делаю не так?

Ответы [ 4 ]

3 голосов
/ 16 июня 2011

Вам нужно написать вызов метода следующим образом:

cell = [self myCell:cell forRowIndex:indexPath];

0 голосов
/ 08 февраля 2016

Поскольку при вызове отсутствует подпись метода. Ниже приведена коррекция.

Ваш звонок:

cell = [self myCell:cell:indexPath]; //code crashing here...! 

Фактический звонок:

cell = [self myCell:cell forRowIndex:indexPath]; // It'll work for sure as we following the correct method signature from your above code.
0 голосов
/ 08 сентября 2015

Вам нужно написать вызов метода следующим образом:

if(cell == nil)   
{
       cell = [[[NSBundle mainBundle] loadNibNamed:@"ResultsOne"owner:self options:nil] objectAtIndex:0];          
}

Затем вы позвоните:

cell = [self myCell:cell forRowIndex:indexPath];

0 голосов
/ 16 июня 2011

проверьте подпись метода "myCell:". как заметил @Robert Fratto, это может быть что-то еще.
Документ гласит:
[myRectangle setOrigin:30.0 :50.0]; // This is a bad example of multiple arguments<br> Since the colons are part of the method name, the method is named setOrigin::. It has two colons as it takes two arguments. This particular method does not interleave the method name with the arguments and, thus, the second argument is effectively unlabeled and it is difficult to determine the kind or purpose of the method’s arguments.

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