Проблема памяти с базовым UITableView при прокрутке - PullRequest
2 голосов
/ 24 мая 2010

У меня есть очень простой UITableView, который имеет 3 секции и 3 строки на секцию.

#pragma mark -
#pragma mark UITableView delegate methods

- (NSInteger)tableView:(UITableView *)tblView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tblView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    // Configure the cell...

    return cell;

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tblView 
{ 
    if (tblView == self.tableView) {
        return 3;
    }
    else {
        return 1; 
    }
}

Все отображается нормально, но как только я прокручиваю приложение, происходит сбой и мой отладчик говорит мне:

***** - [ProfileViewController tableView: cellForRowAtIndexPath:]: сообщение отправлено на освобожденный экземпляр 0x5ae61b0 **

Я не совсем уверен, что я делаю неправильно.* РЕДАКТИРОВАТЬ: Вот как я отображаю ProfileViewController:

ProfileViewController* profileView = [[ProfileViewController alloc] initWithNibName:@"ProfileViewController" bundle:nil];
    profileView.user_name = username;
    profileView.message_source = messageSource;
    [self.navigationController pushViewController:profileView animated:YES];
    [profileView release];

Ответы [ 4 ]

2 голосов
/ 24 мая 2010

Похоже, что ваш ProfileViewController экземпляр как-то освобожден.Убедитесь, что вы не вызываете его -autorelease после его создания.

1 голос
/ 24 мая 2010

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

0 голосов
/ 07 декабря 2010

Вместо использования

cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: CellIdentifier] autorelease];

используйте

cell = [[[UITableViewCell alloc] initWithFrame: CGRectZero reuseIdentifier: CellIdentifier] autorelease];

И измените код своей реализации следующим образом:

Не используйте приведенный ниже код в методе cellForRowAtIndexPath.Вместо этого используйте в методе "didSelectRowAtIndex".

В файле заголовка (.h):

ProfileViewController * profileView;

В реализации (.m) файл:

if (profileView == nil) profileView = [[ProfileViewController alloc] initWithNibName: @ "ProfileViewController" bundle: nil];profileView.user_name = username;profileView.message_source = messageSource;[self.navigationController pushViewController: profileView animated: YES];

0 голосов
/ 30 августа 2010

что-то, что помогло мне с подобной проблемой, заключалось в следующем: вам может понадобиться сохранить контроллер табличного представления, настроив его как IBOutlet, если это подпредставление другого представления - т.е.удержание ребенка.

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