2013-08-17 1 views
0

좋아, 여기서는 작동하지 않는 알고리즘을 작성했습니다. 기본적으로 여러 페이지에 걸쳐 버튼 목록을 그립니다. iPhone 4에서 페이지 당 4 개의 버튼이 그려지며, iPhone 4S에서는 3 개의 버튼이 그려집니다. 때문에 캐치되지 않는 예외에'NSInvalidArgumentException'이라는 캐치가 발생하지 않는 예외로 인해 앱이 종료됩니다. 이유 : '- [__ NSCFArray length] : 인식 할 수없는 선택기가 인스턴스로 전송되었습니다.

응용 프로그램을 종료 :

그러나 어떤 이유로

는 'setFrame'방식으로,이 오류가

'NSInvalidArgumentException', reason: '-[__NSCFArray length]: unrecognized selector sent to instance 

이상한 것은 그 어디에도 알고리즘에서, 또는 없다 앱의 어느 곳에서도 메소드 length];이 호출됩니다.

또한이 방법을 사용할 때는 아무 것도하지 않으며, NSArrays에는 아무런 방법이 없다는 것을 알아 두십시오. length.

// creates the chapters 
+(void)createChapterInScrollView:(UIScrollView *)scrollview withArray:(NSArray *)array withTarget:(id)target andMethod:(SEL)method 
{ 
    // sets up some initial variable 
    int x = 20; 
    int y = 40; 

    // fills an array with the y values 
    int yValues; 
    NSMutableArray *yContainer = [[NSMutableArray alloc] init]; 
    if (screenHeight == 568) { 
     yValues = 4; 
    } else { 
     yValues = 3; 
    } 
    for (yValues = yValues; yValues > 0; yValues = yValues - 1) { 
     [yContainer addObject:[NSString stringWithFormat:@"%i", y]]; 
     y = y + 70; 
    } 

    // creates the buttons using the number of pages 
    int numOfpages = [self numOfPagesFromArray:array]; 
    int numofPagesLeft = [self numOfPagesFromArray:array]; 
    int numOfButtonsLeft = [array count]; 
    int currentButton = 0; 

    if (numofPagesLeft == 0) { 

    } else { 
     for (numofPagesLeft = numofPagesLeft; numofPagesLeft >= 0; numofPagesLeft = numofPagesLeft - 1) { 
      for (id object in yContainer) { 
       if (numOfButtonsLeft > 0) { 
        UIButton *newButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
        [newButton setTitle:[array objectAtIndex:currentButton] forState:UIControlStateNormal]; 
        [newButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted]; 
        [newButton setFrame:CGRectMake(x, [object floatValue], 280, 50)]; 
        [newButton setTag:(currentButton+1)]; 
        [newButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft]; 
        [newButton.titleLabel setTextAlignment:NSTextAlignmentLeft]; 
        [newButton addTarget:target action:method forControlEvents:UIControlEventTouchUpInside]; 
        [scrollview addSubview:newButton]; 
        numOfButtonsLeft = numOfButtonsLeft - 1; 
        currentButton ++; 
       } 
      } 
      x = x + 320; 
     } 
    } 

    // checks if any buttons were actually created 
    if (numOfpages == 0) { 
     // tells the user that no content has been downloaded 
     UILabel *errorLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 300, 216)]; 
     [errorLabel setBackgroundColor:[UIColor clearColor]]; 
     [errorLabel setTextColor:[UIColor whiteColor]]; 
     [errorLabel setNumberOfLines:10]; 
     [errorLabel setFont:[UIFont systemFontOfSize:17]]; 
     [errorLabel setTextAlignment:NSTextAlignmentCenter]; 
     [errorLabel setText:@"Oops!\n\nLooks like no readable content has been downloaded!\n\nThe content will be automatically downloaded right now!"]; 
     [scrollview addSubview:errorLabel]; 
    } 
} 

고마워 :

여기 알고리즘입니다!

+0

numOfPagesFromArray 메서드를 표시 할 수 있습니까? – David

+0

'screenheight'는 어디에 정의되어 있습니까? –

+0

좀비 도구 아래에서 실행하십시오. –

답변

0

Xcode에서 중단 점 탐색기로 이동하여 예외 중단 점을 추가하십시오. 간단한 설명 방법은 in this SO answer

이 있으면 일단 어떤 코드 줄에서 예외가 발생하는지 정확히 확인해야합니다.

관련 문제