簡體   English   中英

滾動時iOS UITableView崩潰

[英]iOS UITableView crashes when scrolling

我在這里遇到了一個奇怪的問題。 我正在開發一個iOS應用程序(專門針對iPad),並且在某些時候使用UITableView來顯示事物列表。

現在,當我在視圖范圍內滾動時(不在第一個元素上方,也不在最后一個元素下方),它可以正常工作。 但是,當我進一步滾動時,它只會崩潰,沒有其他消息:

  • 向下滾動到最后一個元素時為EXC_BAD_ACCESS
  • 當我滾動到第一個之上時, SIGABRT具有回溯

我在Google上瀏覽時,似乎釋放了太多對象,但是我不知道是哪個對象。

我也嘗試過在Instruments內運行該應用程序,但是每次運行該應用程序時,Instruments窗口都會凍結,迫使我用手殺死它...當然,我沒有得到任何結果...

這里是一些相關的代碼:

    /*
     Returns the cells of the table view
     */
    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        // Create a new cell view
        static NSString *CellIdentifier = @"Cell";

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

        // Configure the cell...
        cell.textLabel.text = [newestModules objectAtIndex:indexPath.row];
        cell.textLabel.textColor = [UIColor whiteColor];
        cell.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"Background-Texture-Dark-Small.png"]];
        cell.imageView.image = [UIImage imageNamed:@"Icon-Maths.png"];

        UIView *v = [[[UIView alloc] initWithFrame:cell.frame] autorelease];

        // Set view background color
        v.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Background-Texture-Dark-Small.png"]];

        // This view will be activated when the cell is selected
        cell.selectedBackgroundView = v;

        return cell;
    }

編輯:UITableView加載和卸載方法:

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Transparent background
    self.tableView.backgroundView = nil;

    // Generate list of newest modules. Will later look for them on the internet, but for now we only add some test examples.
    newestModules = [[NSMutableArray alloc] initWithObjects:@"Test 1", @"Test 2", @"Test 3", @"Test 4", @"Test 5", nil];
}

- (void)viewDidUnload
{
    [newestModules release];
    [super viewDidUnload];
}

似乎在Interface Builder中添加對象(如新控制器)時,默認情況下會自動釋放該對象。

如果不將其與類中的保留屬性鏈接,則在初始化后立即釋放它,從而導致可怕的EXC_BAD_ACCESS錯誤。

根據經驗,邊界滾動和邊界滾動之間的最大區別在於,邊界滾動經過表的所有元素(包括頁眉和頁腳),並且很可能會重新計算行數。 如果您有頁眉和頁腳,請嘗試在其中放置斷點。

關於EXC_BAD_ACCESS,可以在malloc_error_break中放置一個斷點,以期希望更多地了解誰未正確釋放。 這是一個符號斷點,可通過“斷點”窗口上的“ +”按鈕進行定義。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM