2013-07-05 33 views
5

Bỏ qua tất cả thông tin này và chuyển sang cập nhật ở phía dưới ...numberOfSections được gọi? iOS

tôi đã xử lý với bộ chọn không được công nhận trước đó, nhưng tôi không thể tìm ra những gì đang xảy ra thời gian này. Các ngăn xếp cuộc gọi là mờ đục và tôi không thể tìm ra nơi mà vấn đề có nguồn gốc từ. Tôi đã thử sử dụng các điểm ngắt biểu tượng và ngoại lệ. Mã này đã được làm việc một cách hoàn hảo before..I trở về làm việc về chương trình này một số chi tiết và bây giờ chạy vào này

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

Tôi có hai UITableViews trong điều khiển điểm này. Một trong số chúng được nối trong IB(datasource and delegate). Thứ hai được khởi tạo trong mã và nguồn dữ liệu/đại biểu của nó cũng trỏ đến bộ điều khiển xem. Tôi đặt một thẻ của 2 vào tableview thứ hai để phân biệt chúng với nhau. UITableViewTwo được thêm vào một số UIView được trả lại làm chân trang của chế độ xem bảng đầu tiên nếu tôi có dữ liệu hợp lệ để hiển thị. Một lần nữa, đoạn mã này đã hoạt động hoàn hảo mà không gặp bất kỳ sự cố nào trong khi quay lại, và tôi dường như không thể hiểu tại sao nó lại bị hỏng. Tôi đang sử dụng ARC.

Dưới đây là một số mã:

Khi tôi kiểm tra những địa chỉ của đối tượng chọn được gửi đến là: nó thực sự là một UITableViewSectionElement. Tại sao H lại nhận được số gọi làOfSections? Nó không phải là 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; 
} 

Xem Đã tải (Các thông tin liên quan):

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]; 

Tôi gắn một số ảnh chụp màn hình của ứng dụng:

Bất cứ khi nào tôi bấm vào hoặc cố gắng để di chuyển tableviewTwo tôi nhận vụ tai nạn này.

App Image TB2 crash log 1 crash log 2 properties

Cập nhật:

breakpoint

Đây là những gì nó cho thấy khi tôi di chuyển thứ hai UITableView (với tất cả các trường hợp ngoại lệ cho phép):

first line shown after clicking continue

Tôi có một bản dựng này hoạt động hoàn hảo trên điện thoại của tôi (cách đây một tháng) .. Tôi không biết tại sao tôi gặp lỗi này ngay bây giờ. Có thể thay đổi nếu Trình tạo giao diện đã gây ra điều này không? Tôi đã kiểm tra tất cả các cửa hàng và bao gồm chúng. Cảm ơn ..

Cập nhật:

Thật kỳ lạ khi tôi sao chép bản ghi trên máy tính xách tay khác đang hoạt động mà không gặp sự cố. Tôi nghĩ bằng cách nào đó dự án tôi đang sử dụng đã bị hỏng? Tôi sẽ về nhà và điều tra thêm.

Bất kỳ ý tưởng nào về lý do tại sao điều này không bị treo trên máy tính xách tay công việc của tôi (thông số kỹ thuật tương tự) và đang gặp sự cố trên máy tính xách tay của tôi. Tôi đã nhân bản các thư mục git trong cả hai máy tính xách tay và tôi nhận được một vụ tai nạn ở đây, nhưng không phải ở đó. Tôi đang chạy phiên bản XCode 4.6.3 trên máy tính xách tay của mình.

Cập nhật 2:

Nó không còn hoạt động trên máy tính xách tay công việc của tôi..WTF đang diễn ra? Có lỗi trong Xcode 4.6.3 không? Tôi có thể làm gì để khắc phục sự cố này thêm không? Tại sao numberOfSections được gọi? Tôi không thể tìm thấy tài liệu trên BẤT CỨ trực tuyến đó.

Cập nhật 3:

Được rồi, nó chỉ ra rằng dòng mã này trong bộ chọn viewForFooterInSection là thủ phạm:

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

Nó hoạt động tốt trên các thiết bị nhưng tai nạn trên giả lập. Khi tôi chỉ đơn giản là thay đổi nó sau đây .. nó hoạt động.

return tableViewTwo; 

Có ai biết tại sao trả lại tableview trong một cái nhìn được đưa ra một lỗi?

+2

Đó 'tableView: cellForRowAtIndexPath: 'phương pháp ** cầu xin ** cho refactoring. –

+0

@ H2CO3 Tôi chắc chắn đồng ý với bạn về điều này. Tuy nhiên, tôi không thấy bất kỳ điều gì sai với bộ chọn ** đó ** – kamran619

+0

Vậy phương thức 'numberOfSections' của bạn ở đâu? –

Trả lời

1

numberOfSections là phương thức trên UITableView - đó không phải là phương thức đại biểu. Có vẻ như hệ thống gọi phương thức này trong nội bộ và vì lý do nào đó, bảng của bạn được phát hành tự động (do đó sự cố).

tôi sẽ cố gắng sau trong phương pháp viewForFooterInSection của bạn:

static UIView *view = nil; 

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

return view; 
+0

Hey, tôi nghĩ rằng điều này sẽ làm việc, nhưng nó đã không: (cùng một vấn đề. – kamran619

+0

Bạn đã thử những điều sau đây để theo dõi tốt hơn vấn đề: .1 Kích hoạt zombie: http://stackoverflow.com/questions/2190227/ how-do-i-set-up-nszombieenabled-in-xcode-4 và 2. Chạy trình phân tích tĩnh: http://stackoverflow.com/questions/5650771/clang-static-analyzer-for-xcode4 –

+0

Tôi có. .một trong số đó đã giúp. – kamran619

0

Bạn vừa đề cập đến việc bạn đang sử dụng ARC, do đó bạn đã tạo Bảng nhìn thứ hai của mình Một thuộc tính mạnh mẽ? nó là một cây ngà?

Vấn đề là nếu bạn không biến nó thành tài sản mạnh, nó cuối cùng sẽ được giải phóng nhờ ARC và bạn sẽ không thể biết được vấn đề, bạn có thể đăng mã từ tệp .h không?

+0

Tệp .h được đăng dưới dạng ảnh chụp màn hình. Nó thực sự được tuyên bố là một tài sản mạnh mẽ. – kamran619