2010-12-29 4 views
4

테이블의 행 수를 0으로 설정하면 내 UITableView에서 일관된 충돌이 발생합니다. EXC_BAD_ACCESS 오류로 인해 충돌합니다. 충돌은 UITableView 내부에서 발생하므로 잘못된 부분을 직접 볼 수는 없지만 내 부분에서는 어리석은 실수가되어야합니다. 다음과 같이EXC_BAD_ACCESS 행 수가 0 일 때 UITableView에서 크래시가 발생합니다.

스택 추적 :

#0 0x0194ca60 in objc_msgSend() 
#1 0x00656837 in -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:]() 
#2 0x0064c77f in -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:]() 
#3 0x00661450 in -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:]() 
#4 0x00659538 in -[UITableView layoutSubviews]() 
#5 0x00d39451 in -[CALayer layoutSublayers]() 
#6 0x00d3917c in CALayerLayoutIfNeeded() 
#7 0x00d3237c in CA::Context::commit_transaction() 
#8 0x00d320d0 in CA::Transaction::commit() 
#9 0x00d627d5 in CA::Transaction::observer_callback() 
#10 0x013a3fbb in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__() 
#11 0x013390e7 in __CFRunLoopDoObservers() 
#12 0x01301bd7 in __CFRunLoopRun() 
#13 0x01301240 in CFRunLoopRunSpecific() 
#14 0x01301161 in CFRunLoopRunInMode() 
#15 0x01d42268 in GSEventRunModal() 
#16 0x01d4232d in GSEventRun() 
#17 0x005f142e in UIApplicationMain() 
#18 0x000518ec in main (argc=1, argv=0xbfffef84) at /Users/megahub/xcode/QuamSec/main.m:15 

를 다음과 같이 내 코드는 다음과 같습니다

- (id)initWithFrame:(CGRect)frame { 

     self = [super initWithFrame:frame]; 
     if (self) { 

      m_oPositionTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 367) style:UITableViewStylePlain]; 
      m_oPositionTableView.delegate = self; 
      m_oPositionTableView.dataSource = self; 
      m_oPositionTableView.separatorStyle = UITableViewCellSeparatorStyleNone; 

      [self addSubview:m_oPositionTableView]; 

      m_oAppDelegate = (AyersGTSAppDelegate *)[[UIApplication sharedApplication] delegate]; 

     } 
     return self; 
    } 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    // Return the number of sections. 
    return 1; 
} 


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    // Return the number of rows in the section. 
    if (m_oPositionItems == nil) 
     return 0; 
    else 
     return [m_oPositionItems count]; 
} 


// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"QuamPortfolioPositionCell"; 

    QuamPortfolioPositionCell *cell = (QuamPortfolioPositionCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[NSBundle mainBundle] loadNibNamed:@"QuamPortfolioPositionCell" owner:self options:nil] lastObject]; 
    } 

    // Configure the cell... 
    SPPositionItem *oPositionItem = [m_oPositionItems objectAtIndex:indexPath.row]; 
    cell.oSymbol.text = oPositionItem.sProdCode; 
    cell.oMktPrice.text = oPositionItem.sMktPrice; 
    cell.oNet.text = oPositionItem.sNet; 
    cell.oAmount.text = oPositionItem.sMktVal; 

    return cell; 
} 

내가 하드 코딩 경우 테이블의 행 수가 0 일 때 충돌에만 발생 행 수가 1로 반환되면 충돌이 나타나지 않습니다.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 

하지 jQuery과 셀 그래서

if (m_oPositionItems == nil) 
    return 1; 
else 
    return [m_oPositionItems count]; 

트릭을 할해야

없이 빈 테이블을 그릴 수 없기 때문입니다 0 을 반환 할 수 있기 때문이다

+0

NSZombieEnabled를 켜면 어떤 할당 취소 된 객체에 액세스했는지 확인할 수 있습니다. –

+0

이전 초기화 함수에서 테이블 셀을 반환하는 것을 잊어 버렸습니다. 모두 고쳐졌습니다. – futureelite7

+0

답안으로 작성하고 직접 받아 들여야합니다. 그렇게하면 질문에 답이 표시되고 다른 사람이 검색하면 솔루션을 더 쉽게 찾을 수 있고 스스로 해결할 수도 있습니다. 자신의 질문에 답하고 그 대답을 받아 들일 만하다고 완벽하게 받아 들일 수 있습니다. (당신은 그것에 대해 어떤 대표도 얻지 못합니다.) –

답변

3

이전 초기화 기능에서 테이블 셀을 반환하는 것을 잊어 버렸습니다. 모두 고쳐졌습니다.

+0

응용 프로그램을 컴파일 할 때 경고로 표시되면 안됩니까? –

+0

예 ... 간과했습니다. – futureelite7

-7

아니라.

+5

전혀 사실이 아닙니다. 섹션에는 0 행, 테이블에는 0 행을 절대 가질 수 있습니다. S/그는 우리가 가지고있는 맥락의 양을 감안할 때 실제로 추론 할 수없는 몇 가지 다른 기억 문제를 가지고 있습니다. –

관련 문제