2009-10-03 10 views
5

다운로드 한 예제에서 열어 본 더 복잡한 셀과 비교할 때 너무 느린 경우에도 오류없이 작동하는이 큰 테이블이 있습니다. 문제는 내가 셀을 클릭 할 때 제공 한 다음 앱이 라인에 충돌되어 빠른 스크롤의 몇 초에 돌아왔다 : 나는 다음 줄에 충돌되어 삭제하면 charImage.image = [self imageForIndex:ch.charId];왜 내 앱이 충돌하나요? UITable 및 컨트롤러

: titleLabel.text = ch.title;

는 누구인가 이걸 잘 알고 있니? 감사.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
//NSLog(@"add a new cell at index path %@", indexPath); 
// Each subview in the cell will be identified by a unique tag. 
static NSUInteger const kTitleLabelTag = 2; 
static NSUInteger const kCharImageTag = 3; 
static NSString *kCellID = @"CellID"; 

// Configure the cell 


// Declare references to the subviews which will display the char data. 
UILabel *titleLabel = nil; 
UIImageView *charImage = nil; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellID]; 

if (cell == nil) { 
    // No reusable cell was available, so we create a new cell and configure its subviews. 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellID] autorelease]; 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    [cell setBackgroundColor:[UIColor clearColor]]; 
    // 
    charImage = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"glyphs/a/1.png"]] autorelease]; 
    charImage.tag = kCharImageTag; 
    charImage.autoresizingMask = UIViewAutoresizingNone; 
    [cell.contentView addSubview:charImage]; 

    titleLabel = [[[UILabel alloc] initWithFrame:CGRectMake(60, 10, 215, 20)] autorelease]; 
    titleLabel.tag = kTitleLabelTag; 
    titleLabel.font = [UIFont systemFontOfSize:16]; 
    titleLabel.textColor = [UIColor whiteColor]; 
    titleLabel.backgroundColor = [UIColor clearColor]; 
    titleLabel.adjustsFontSizeToFitWidth = YES; 
    [cell.contentView addSubview:titleLabel]; 

} else { 
    // A reusable cell was available, so we just need to get a reference to the subviews using their tags. 
    charImage = (UIImageView *)[cell.contentView viewWithTag:kCharImageTag]; 
    titleLabel = (UILabel *)[cell.contentView viewWithTag:kTitleLabelTag]; 
} 


// Get the specific info for this row. 
NSUInteger section = [indexPath section]; 
NSUInteger row = [indexPath row]; 
Char *ch = (Char *)[charsList objectAtIndex:row+section*26]; 

// Set the relevant data for each subview in the cell. 
// Set the image in the cell 
charImage.image = [self imageForIndex:ch.charId]; 
[charImage sizeToFit]; 

int centerX = 30; 
int centerY = 23; 
CGSize size = charImage.frame.size; 
charImage.frame = CGRectMake((int)(centerX - size.width/2), 
          (int)(centerY - size.height/2), 
          size.width, size.height); 

titleLabel.text = ch.title; 

return cell; 

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

InstantInsightAppDelegate *delegate = [[UIApplication sharedApplication] delegate]; 
NSUInteger section = [indexPath section]; 
NSUInteger row = [indexPath row]; 
Char *ch = (Char *)[charsList objectAtIndex:row+26*section]; 

SqlQueries *db = [SqlQueries alloc]; 
NSArray *glyphsList = [db readGlyphsFromDatabaseAtId: ch.charId]; 
NSArray *charDescription = [db readMoreInfoFromDatabaseAtId: ch.charId]; 
Char *charDetails = [db readInstructionsAndQuotesFromDatabaseAtId: ch.charId]; 
[db release]; 
[ch release]; 

// Navigation logic -- create and push a new view controller 
self.glyphsView = [[GlyphsViewController alloc] initWithStyle:UITableViewStyleGrouped]; 

self.glyphsView.glyphsList = glyphsList; 
self.glyphsView.charDetails = charDetails; 
self.glyphsView.charDescription = charDescription; 
[delegate.navController pushViewController:self.glyphsView animated:YES]; 
[self.glyphsView release]; 
self.glyphsView = nil; 

은} 여기


상세한 오류입니다 : 그것은 아무 말도하지 않고 나는 예외 뭔가를 본 적이 확신

[세션 시작일 : 2009-10-05 07:41:25 +0300] GNU gdb 6.3.50-20050815 (Apple 버전 gdb-967) (Tue Jul 14 02:11:58 UTC 2009) Copyright 2004 Free Software Foundation, Inc. GDB는 GNU 일반 공중 사용 허가서의 적용을받는 무료 소프트웨어이며, 귀하는 환영합니다. 정황. "show copying"를 입력하여 조건을 확인하십시오. GDB에 대한 어떠한 보증도 없습니다. 자세한 내용은 "보증 표시"를 입력하십시오. 이 GDB는 "I386 - 사과 - 다윈"로 구성된에게 적용-로드 규칙을 .sharedlibrary 모든 96464. (GDB)^C 을 처리하기 위해 부착 위치를

#0 0x95fd5688 in objc_msgSend() 
#1 0x00002f60 in -[IndexViewController tableView:cellForRowAtIndexPath:] (self=0xd19610, _cmd=0x319a6b9c, tableView=0x101be00, indexPath=0xd2e890) at /Users/Cristi/Documents/xcode - iPhone/Instant Insight/InstantInsight/Classes/IndexViewController.m:115 
#2 0x30944bd0 in -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:]() 
#3 0x3093e1fc in -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:]() 
#4 0x309501f1 in -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow]() 
#5 0x30947715 in -[UITableView layoutSubviews]() 
#6 0x00b3dd94 in -[CALayer layoutSublayers]() 
#7 0x00b3db55 in CALayerLayoutIfNeeded() 
#8 0x00b3d3ae in CA::Context::commit_transaction() 
#9 0x00b3d022 in CA::Transaction::commit() 
#10 0x00b452e0 in CA::Transaction::observer_callback() 
#11 0x30245c32 in __CFRunLoopDoObservers() 
#12 0x3024503f in CFRunLoopRunSpecific() 
#13 0x30244628 in CFRunLoopRunInMode() 
#14 0x32044c31 in GSEventRunModal() 
#15 0x32044cf6 in GSEventRun() 
#16 0x309021ee in UIApplicationMain() 
#17 0x00002718 in main (argc=1, argv=0xbfffee50) at /Users/Cristi/Documents/xcode - iPhone/Instant Insight/InstantInsight/main.m:14 
+0

Char * ch = (Char *) [charsList objectAtIndex : row + section * 26]; 저에게 아주 이상하게 보입니다. charsList에 어떤 종류의 객체를 넣을까요? – diederikh

+0

Char 객체를 넣습니다. Char는 데이터베이스에서 채워지는 NSString 만 포함합니다. 만약 내가 단순히 NSLog이 값을, 그들은 괜찮아요, 심지어 시간에 충돌합니다. –

답변

5

"충돌"어떤 종류의? EXC_BAD_ACCESS (유효한 위치를 가리 키지 않는 포인터 역 참조)? 아니면 어떤 종류의 objc_exception_throw? 당신을 가정

의미 EXC_BAD_ACCESS ...

[charsList objectAtIndex:row+section*26]에서 반환 된 "채널"값이 유효한 대상이 아니기 때문에이 될 것입니다.

자신을 발견해야 할 정확한 이유가 있지만 가장 많은 원인은 개체를 너무 여러 번 릴리스했다는 것입니다. 오브젝트가 NSArray에 삽입되었을 때 유효한 Objective-C 오브젝트가 아닌 가능성도 있습니다.

때로는 NSZombieEnabled (command-option-x, Arguments 탭으로 이동하여 name = NSZombieEnabled 및 value = 1을 환경 변수에 추가하는 데 도움이됩니다). 할당 해제 된 코드를 사용하려고하면 예외가 즉시 throw됩니다. 목적.

-

관련없는 문체 점 : 당신이 SqlQueries를 할당하지만 초기화 아닙니다. alloc 인 경우 항상 항상 init입니다. 즉 [[SqlQueries alloc] init]입니다. init 인스턴스 변수가 없기 때문에 alloc을 사용하지 않아도된다면 메소드는 대신 클래스 메소드 여야합니다.

+0

자세한 설명해 주셔서 감사합니다. 나는 내가 SqlQueries의 init에 뭔가를 넣을 수 있다고 생각한다. 이제는 예외가있는 오류라고 생각합니다. try catch를 사용한다는 생각이 들기 때문에 슬프게도 여전히 충돌이 발생하지만 catch의 nslog는 호출되지 않습니다. 내 코드에 대해 무엇을 말할지 모르겠습니다. –

+0

EXC_BAD_ACCESS를 잡지 못합니다. charList의 객체가 유효하지 않은 이유를 찾아야합니다. 디버거에서 중단 점을 사용하거나 정기적으로 전체 charList를 NSLog로 잘못 판단합니다 (charList 객체가 무효화되면 NSLog가 프로그램을 중단시킵니다). Char 객체가 아직 할당되지 않았거나 보유되지 않은 상태에서 Char 객체 중 하나를 릴리스 (또는 자동 렌더링)하는 코드가있을 가능성이 있습니다. char 객체가 여전히 필요하지만 Char 객체가 무효화되는 원인이됩니다. 정렬. –

+0

그래, 네가 말했듯이 내가 배열에서 Char 객체를 deallocing하는지 더 자세히 보았다. 나는 그것을하고 있었다. 대답은이 행을 삭제하는 것입니다 : [ch release]; 다시 한 번 감사드립니다. –

관련 문제