2013-07-05 16 views
5

Przejdź wszystkie te informacje i przejść do aktualizacji na dole ...NumerOfSections jest wywoływana? iOS

I mieć do czynienia z selektorów nierozpoznanych wcześniej, ale nie mogę dowiedzieć się, co się dzieje w tej chwili. Stos wywołań jest nieprzejrzysty i nie mogę się dowiedzieć, skąd się bierze problem. Próbowałem używać punktów przerwania symbolicznego i wyjątku. Ten kod działa doskonale before..I wrócić do pracy nad tym programem niektóre więcej i teraz pracuje w tej

[UITableViewSectionElement numberOfSections]: unrecognized selector sent to instance 0xa285d50 

Mam dwie UITableViews w tym kontrolerze widoku. Jeden z nich jest podłączony do IB(datasource and delegate). Drugi jest tworzony w kodzie, a jego źródło/delegat wskazuje również kontroler widoku. W drugim widoku tabeli umieściłem znacznik 2, aby odróżnić je od siebie. UITableViewTwo jest dodawana do UIView, która jest zwracana jako stopka pierwszego widoku tabeli, jeśli mam prawidłowe dane do wyświetlenia. Znowu ten kod działał idealnie bez żadnych awarii po chwili i nie mogę się domyślić, dlaczego teraz się zawiesza. Używam ARC.

Oto kod:

Kiedy sprawdzić co adres obiektu selektor wysyłane do jest: to jest rzeczywiście UITableViewSectionElement. Dlaczego H jest tym, który odbiera numer wywołania? Czy to nie powinno być numberOfSectionsInTableView?

UITableView Delegate/DataSource methods 

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (tableView.tag == 0) { 
     if (indexPath.row == 0) { 
      PCFCustomNumberReviewsCell *cell = [self.tableViewOne dequeueReusableCellWithIdentifier:@"PCFNumberOfRatings"]; 
      [cell.numberOfReviews setText:[NSString stringWithFormat:@"%d", numReviews.integerValue]]; 
      [cell.numberOfReviews setFont:[PCFFontFactory droidSansFontWithSize:17]]; 
      [cell.numberOfReviews setTextColor:[UIColor lightGrayColor]]; 
      UIImageView *imgView = [[UIImageView alloc] initWithFrame:cell.frame]; 
      [imgView setImage:[UIImage imageNamed:@"1slot2.png"]]; 
      [cell setBackgroundView:imgView]; 
      return cell; 
     }else if(indexPath.row == 1) { 
      PCFCustomReviewCell *cell = [self.tableViewOne dequeueReusableCellWithIdentifier:@"RateEasiness"]; 
      [cell.stars setBackgroundImage:[self getImageForStars:[NSString stringWithFormat:@"%d", totalEasiness.integerValue]] forState:UIControlStateNormal]; 
      UIImageView *imgView = [[UIImageView alloc] initWithFrame:cell.frame]; 
      [imgView setImage:[UIImage imageNamed:@"1slot2.png"]]; 
      [cell setBackgroundView:imgView]; 
      return cell; 
     }else if(indexPath.row == 2) { 
      PCFCustomReviewCell *cell = [self.tableViewOne dequeueReusableCellWithIdentifier:@"RateUsefulness"]; 
      [cell.stars setBackgroundImage:[self getImageForStars:[NSString stringWithFormat:@"%d", totalUsefulness.integerValue]] forState:UIControlStateNormal]; 
      UIImageView *imgView = [[UIImageView alloc] initWithFrame:cell.frame]; 
      [imgView setImage:[UIImage imageNamed:@"1slot2.png"]]; 
      [cell setBackgroundView:imgView]; 
      return cell; 
     }else if(indexPath.row == 3) { 
      PCFCustomReviewCell *cell = [self.tableViewOne dequeueReusableCellWithIdentifier:@"RateFunness"]; 
      [cell.stars setBackgroundImage:[self getImageForStars:[NSString stringWithFormat:@"%d", totalFunness.integerValue]] forState:UIControlStateNormal]; 
      UIImageView *imgView = [[UIImageView alloc] initWithFrame:cell.frame]; 
      [imgView setImage:[UIImage imageNamed:@"1slot2.png"]]; 
      [cell setBackgroundView:imgView]; 
      return cell; 
     }else if(indexPath.row == 4) { 
      PCFCustomReviewCell *cell = [self.tableViewOne dequeueReusableCellWithIdentifier:@"RateInterestLevel"]; 
      [cell.stars setBackgroundImage:[self getImageForStars:[NSString stringWithFormat:@"%d", totalInterestLevel.integerValue]] forState:UIControlStateNormal]; 
      UIImageView *imgView = [[UIImageView alloc] initWithFrame:cell.frame]; 
      [imgView setImage:[UIImage imageNamed:@"1slot2.png"]]; 
      [cell setBackgroundView:imgView]; 
      return cell; 
     }else if(indexPath.row == 5) { 
      PCFCustomReviewCell *cell = [self.tableViewOne dequeueReusableCellWithIdentifier:@"RateTexbookUse"]; 
      [cell.stars setBackgroundImage:[self getImageForStars:[NSString stringWithFormat:@"%d", totalTextbookUse.integerValue]] forState:UIControlStateNormal]; 
      UIImageView *imgView = [[UIImageView alloc] initWithFrame:cell.frame]; 
      [imgView setImage:[UIImage imageNamed:@"1slot2.png"]]; 
      [cell setBackgroundView:imgView]; 
      return cell; 
     }else if(indexPath.row == 6) { 
      PCFCustomReviewCell *cell = [self.tableViewOne dequeueReusableCellWithIdentifier:@"RateOverall"]; 
      [cell.stars setBackgroundImage:[self getImageForStars:[NSString stringWithFormat:@"%d", totalOverall.integerValue]] forState:UIControlStateNormal]; 
      UIImageView *imgView = [[UIImageView alloc] initWithFrame:cell.frame]; 
      [imgView setImage:[UIImage imageNamed:@"1slot2.png"]]; 
      [cell setBackgroundView:imgView]; 
      return cell; 
     } 

    }else { 
     PCFCustomCourseCommentCell *cell = (PCFCustomCourseCommentCell *) [self.tableViewTwo dequeueReusableCellWithIdentifier:@"PCFCourseCommentCell"]; 
     if (cell == nil) { 
      NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"PCFCustomCourseReviewCell" owner:self options:nil]; 
      cell = [topLevelObjects objectAtIndex:0]; 
     } 
     UIImageView *imgView = [[UIImageView alloc] initWithFrame:cell.frame]; 
     [imgView setImage:[UIImage imageNamed:@"1slot2.png"]]; 
     [cell setBackgroundView:imgView]; 

     PCFRateModel *rateObject = [courseReviews objectAtIndex:indexPath.section]; 
     [cell.userName setText:rateObject.username]; 
     [cell.date setText:rateObject.date]; 
     [cell.professor setText:rateObject.course]; 
     [cell.comment setText:rateObject.message]; 
     [cell.term setText:rateObject.term]; 
     for (UIView *view in cell.contentView.subviews) { 
      if ([view isMemberOfClass:[UILabel class]]) { 
       UILabel *tempLabel = (UILabel *)view; 
       if ([tempLabel tag] != 0) { 
        [tempLabel setFont:[PCFFontFactory droidSansFontWithSize:tempLabel.tag]]; 
       } 
      } 
     } 
     CGSize size = [rateObject.message sizeWithFont:[PCFFontFactory droidSansFontWithSize:11] constrainedToSize:CGSizeMake(290, 100000)]; 
     [cell.comment setFrame:CGRectMake(cell.comment.frame.origin.x, cell.comment.frame.origin.y, size.width, size.height)]; 
     [cell.comment setBaselineAdjustment:UIBaselineAdjustmentAlignBaselines]; 
     [cell.comment setPreferredMaxLayoutWidth:290]; 
     [cell.comment setLineBreakMode:NSLineBreakByWordWrapping]; 
     [cell.starFunness setBackgroundImage:[self getImageForStars:rateObject.totalClarity] forState:UIControlStateNormal]; 
     [cell.starEasiness setBackgroundImage:[self getImageForStars:rateObject.totalEasiness] forState:UIControlStateNormal]; 
     [cell.starUsefulness setBackgroundImage:[self getImageForStars:rateObject.totalHelpfulness] forState:UIControlStateNormal]; 
     [cell.starInterestLevel setBackgroundImage:[self getImageForStars:rateObject.totalInterestLevel] forState:UIControlStateNormal]; 
     [cell.starOverall setBackgroundImage:[self getImageForStars:rateObject.totalOverall] forState:UIControlStateNormal]; 
     [cell.starTextbookUse setBackgroundImage:[self getImageForStars:rateObject.totalTextbookUse] forState:UIControlStateNormal]; 
     return cell; 
    } 
} 


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    if (tableView.tag == 0) { 
     if (isLoading == YES) { 
      return 0; 
     }else { 
      return 7; 
     } 
    }else { 
     if (isLoadingComments == NO && courseReviews) { 
      return 1; 
     }else { 
      return 0; 
     } 

    } 
} 

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    if (isLoading == YES) return 0; 
    if (tableView.tag != 0) return courseReviews.count; 
    return 1; 
} 

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section 
{ 
    if (section == 0 && tableView.tag == 0) { 
     if (isLoading == YES) { 
      return activityIndicator; 
     }else if (isLoading == NO) { 
      if (isLoadingComments == NO && courseReviews.count > 0) { 
       UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, tableViewTwo.frame.size.height)]; 
       [view addSubview:tableViewTwo]; 
       return view; 
      }else if (isLoadingComments == YES){ 
       UIView *subView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)]; 
       UIActivityIndicatorView *view = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(145, 10, 36, 36)]; 
       [view setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhiteLarge]; 
       [view setColor:[UIColor whiteColor]]; 
       [view startAnimating]; 
       [subView addSubview:view]; 
       return subView; 
      }else if (!courseReviews) { 
       UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 40)]; 
       UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, 320, 30)]; 
       [label setTextColor:[UIColor whiteColor]]; 
       [label setTextAlignment:NSTextAlignmentCenter]; 
       [label setFont:[PCFFontFactory droidSansFontWithSize:22]]; 
       [label setText:@"No Reviews"]; 
       [label setBackgroundColor:[UIColor clearColor]]; 
       [view addSubview:label]; 
       return view; 
      } 

     } 
    } 
    return nil; 
} 
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section 
{ 
    if (tableView.tag == 0) { 
     if (isLoadingComments == NO && courseReviews.count > 0) return tableViewTwo.frame.size.height + 50; 
    } 
    return 5; 
} 
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (tableView.tag == 2) { 
     PCFRateModel *model = [courseReviews objectAtIndex:indexPath.section]; 
     CGSize size = [model.message sizeWithFont:[PCFFontFactory droidSansFontWithSize:11] constrainedToSize:CGSizeMake(290, 100000)]; 
     return (93 + size.height + 10); 
    }else { 
     return tableView.rowHeight; 
    } 
} 

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{ 
    if (section == 0 && tableView.tag == 0) { 
     if ([PCFInAppPurchases boughtRemoveAds] == NO) { 
      if (adView && adView.hidden == NO) { 
       UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 80)]; 
       CGRect frame = adView.frame; 
       frame.origin.y = 0; 
       adView.frame = frame; 
       UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 60, 320, 30)]; 
       [label setNumberOfLines:0]; 
       [label setText:classTitle]; 
       [label setFont:[PCFFontFactory droidSansFontWithSize:14]]; 
       [label setTextColor:[UIColor whiteColor]]; 
       [label setBackgroundColor:[UIColor clearColor]]; 
       [view addSubview:adView]; 
       [view addSubview:label]; 
       return view; 
      } 
     }else { 
      UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 320, 30)]; 
      [label setNumberOfLines:0]; 
      [label setText:classTitle]; 
      [label setFont:[PCFFontFactory droidSansFontWithSize:14]]; 
      [label setTextColor:[UIColor whiteColor]]; 
      [label setBackgroundColor:[UIColor clearColor]]; 
      return label; 

     } 
    } 
    return nil; 
} 

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 
{ 
    if (section == 0 & tableView.tag == 0) { 
     if ([PCFInAppPurchases boughtRemoveAds] == NO) { 
      if (adView && adView.hidden == NO) { 
       return 90; 
      }return 10; 
     }else { 
      return 30; 
     } 

    } 
    return 5; 
} 

View zostały załadowane (stosownych informacji):

tableViewTwo = [[UITableView alloc] initWithFrame:CGRectMake(0, 50, 320, self.view.bounds.size.height) style:UITableViewStyleGrouped]; 
    [tableViewTwo setSectionFooterHeight:0.0f]; 
    [tableViewTwo setDataSource:self]; 
    [tableViewTwo setDelegate:self]; 
    [tableViewTwo setTag:2]; 
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, 320, 30)]; 
    [label setTextColor:[UIColor whiteColor]]; 
    [label setTextAlignment:NSTextAlignmentCenter]; 
    [label setFont:[PCFFontFactory droidSansFontWithSize:22]]; 
    [label setText:@"User Reviews"]; 
    [label setBackgroundColor:[UIColor clearColor]]; 
    [tableViewTwo setTableHeaderView:label]; 
    [tableViewTwo setRowHeight:136]; 
    [tableViewTwo setSectionFooterHeight:.01f]; 
    [tableViewTwo setSectionHeaderHeight:.01f]; 

Załączam kilka zrzutów ekranu z aplikacji:

Gdy kliknę lub spróbuj przewinąć tableviewTwo otrzymuję tę katastrofę.

App Image TB2 crash log 1 crash log 2 properties

Aktualizacja:

breakpoint

To co pokazuje kiedy przewijać drugą UITableView (ze wszystkimi wyjątkami włączone):

first line shown after clicking continue

mam build to doskonale działa na moim telefonie (miesiąc temu) .. nie wiem dlaczego ja dostaję ten błąd teraz. Czy możliwa jest zmiana, jeśli narzędzie do generowania interfejsu spowodowało to? Sprawdziłem wszystkie punkty sprzedaży i uwzględniłem je. Dzięki ..

Aktualizacja:

Co dziwne, kiedy sklonować repo na innym laptopie to działa bez problemów. Myślę, że w jakiś sposób projekt, którego używam, był uszkodzony? Pójdę do domu i zbadam dalej.

Wszelkie sugestie, dlaczego to się nie psuje na moim laptopie pracy (podobne specyfikacje) i awarii na moim laptopie. Sklonowałem katalog git w obu laptopach i dostaję tutaj awarię, ale tam nie. Używam XCode wersji 4.6.3 na moim laptopie.

Aktualizacja 2:

To już nie działa na moją pracę laptop..WTF się dzieje? Czy jest błąd w Xcode 4.6.3? Czy jest coś, co mogę zrobić, aby rozwiązać ten problem dalej? Dlaczego wywoływana jest funkcja numberOfSections? Nie mogę znaleźć dokumentacji tego w Internecie GDZIEKOLWIEK.

Update 3:

Dobrze, okazuje się, że ta linia kodu w selektorze viewForFooterInSection jest winowajcą:

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, tableViewTwo.frame.size.height)]; 
       [view addSubview:tableViewTwo]; 
       return view; 

Działa prawidłowo na urządzeniu, ale wywala na symulatorze. Kiedy po prostu zmienię go na następujący ... działa.

return tableViewTwo; 

Czy ktoś wie, dlaczego zwracanie tableview w widoku powoduje błąd?

+2

że 'Tableview: cellForRowAtIndexPath: metoda' ** ** prosi o refaktoringu. –

+0

@ H2CO3 Zdecydowanie zgadzam się z tobą w tej kwestii. Nadal nie widzę w tym nic złego ** selektor ** – kamran619

+0

Więc gdzie jest twoja metoda 'numberOfSections'? –

Odpowiedz

1

numberOfSections to metoda na UITableView - nie jest to metoda delegowana. Wygląda na to, że system wywołuje tę metodę wewnętrznie iz jakiegoś powodu Twój stół jest automatycznie zwolniony (stąd awaria).

chciałbym spróbować wykonać następujące czynności w sposób viewForFooterInSection:

static UIView *view = nil; 

if (!view) { 
    view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, tableViewTwo.frame.size.height)]; 
    [view addSubview:tableViewTwo]; 
} 

return view; 
+0

Hej, myślałem, że to zadziała, ale nie było :(ten sam problem: – kamran619

+0

Czy próbowałeś następujących sposobów, aby lepiej wyśledzić problem: .1 Włącz zombie: http://stackoverflow.com/questions/2190227/ how-do-i-set-up-nszombieenabled-in-xcode-4 and 2. Uruchom analizator statyczny: http://stackoverflow.com/questions/5650771/clang-static-analyzer-for-xcode4 –

+0

Mam. , z których tylko pomógł, dzięki. – kamran619

0

Właśnie wspomniałeś, że używasz ARC, więc czy zrobiłeś swoją drugą TableView Silną własność? czy to jest ivar?

Problem polega na tym, że jeśli nie uczynisz tego silną własnością, zostanie ona ostatecznie zwolniona dzięki ARC i nie będziesz w stanie poznać problemu, czy możesz umieścić kod z pliku .h?

+0

Plik .h został opublikowany jako zrzut ekranu. Jest to rzeczywiście zadeklarowane jako silna własność. – kamran619

Powiązane problemy