簡體   English   中英

嘗試滾動時,UITableView崩潰(停留了幾個小時)

[英]UITableView crashes when trying to scroll (stuck on this for hours)

我已經嘗試解決這個問題了幾個小時。 當我嘗試滾動時,我的應用程序不斷崩潰。 我查看了可重復使用的部分,但仍然遇到問題。

更新:我正在使用ARC運行xcode 4.2,並且訪問錯誤。

更新2:我嘗試使用“僵屍”定位問題,但仍然無法解決問題。 僵屍屏幕截圖: http : //img440.imageshack.us/img440/7651/instruments.png

更新3 [問題已解決]:我確保ViewDidUnload中的所有出口均為[self set ___:nil]。 我還為添加的視圖創建了一個屬性,而不是在.m文件中創建該視圖。 底部的注釋也幫助了我: 在父視圖控制器被viewDidUnload嘗試dismissModalViewController時獲取“ EXC_BAD_ACCESS”

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [self.sortedKeys count];
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return [self.sortedKeys objectAtIndex:section];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    listData2 =[self.tableContents objectForKey:
    [self.sortedKeys objectAtIndex:section]];
    return [listData2 count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    questionTitle = [[self.tableContents objectForKey:[self.sortedKeys objectAtIndex: [indexPath section]]] objectAtIndex:[indexPath row]];

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Foobar"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Foobar"];
        cell.selectionStyle = UITableViewCellSelectionStyleBlue;
        cell.textLabel.textColor = [UIColor blueColor];
    }

    cell.textLabel.text = questionTitle;

    return cell;
}

跟蹤堆棧將非常有幫助,但是我也相信您應該將listData2 = ..移至viewWillApear:

- (void)viewWillAppear:(BOOL)animated
{
    listData2 =[self.tableContents objectForKey: [self.sortedKeys objectAtIndex:section]];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [listData2 count];
}

另外,嘗試將NSLogs添加到其他UITableView方法中,例如:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    NSLog(@"numberOfSectionsInTableView: self.sortedKeys count: %i",[self.sortedKeys count]);
    return [self.sortedKeys count];
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    NSLog(@"titleForHeaderInSection: self.sortedKeys object: %@"[self.sortedKeys objectAtIndex:section]);
    return [self.sortedKeys objectAtIndex:section];
}

而不是在cellForRowAtIndexPath中設置questionTitle(可能是ViewController的屬性),而是定義一個本地字符串:

NSString *questionTitle2 = ...

然后使用它來設置單元格標簽:

cell.textLabel.text = questionTitle2;

那有什么區別嗎?

暫無
暫無

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

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