2012-12-22 54 views
0

當我動態地添加自定義視圖和我得到這個例外添加Customview到UIScrollView的結果卡住屏幕滾動

例外:;符號存根:GETPID

ITMCustomView *cView = [[ITMCustomView alloc] initWithFrame:CGRectMake(187, 660, 400, 400) 
                 andOrderedItem:@"dd" 
                   andTag:self.tagNumber 
                 withFoldArray:self.foldTypeArray 
                 withRollArray:self.rollTypeArray]; 

    cView.delegate = self; 
     //set properties of cView...like cView.txtName.text [email protected]"John"; 

    //self.scrollView.contentSize = CGRectMake(187, 660, 400, 400).size; 


    /*CGPoint scrollPoint = CGPointMake(0.0, (cView.frame.origin.y/800)*400); 
    [self.scrollView setContentOffset:scrollPoint animated:YES]; 

    [self.scrollView addSubview:cView]; 

    CGFloat scrollViewHeight = 0.0f; 
    for (UIView *view in self.scrollView.subviews) 
    { 
     scrollViewHeight += view.frame.size.height; 
    } 

    CGSize newSize = CGSizeMake(320,scrollViewHeight); 
    //CGRect newFrame = (CGRect){CGPointZero,newSize}; 
    [self.scrollView setContentSize:newSize]; 
    NSLog(@"750 the tag number is %d",self.tagNumber); 
    NSLog(@"the scroll view height is %f",scrollViewHeight); 
    self.currentCGRectLocation = cView.frame;*/ 

有大量的代碼,高於該i的/ * * /。之前也我有一個線

//self.scrollView.contentSize = CGRectMake(187, 660, 400, 400).size; 

如果我去掉上面的行它有評論開始獲得例外。我在我的應用程序的另一個地方來到這個代碼。當我第一次啓動應用程序時,這段代碼被調用並且工作正常。現在我保存在這個屏幕上的記錄-A並去做一些其他的計算(基本上去到另一個屏幕-B),並回到這個屏幕,我檢索保存的記錄並顯示它,只顯示在屏幕A上,然後我得到這個異常。我注意到的是我用滾動視圖做的任何事情都會給出例外。如果我離開了這條線

[self.scrollView addSubview:cView]; 

的意見之外,那麼我可以看到自定義視圖中添加完美fine..but我失去我scrolling..the屏幕是stuck..So問題是有點用滾動視圖我請想想,如果您需要更多信息,請告訴我。謝謝..

編輯:改爲這..靜靜地工作。

 ITMCustomView *cView = [[ITMCustomView alloc] initWithFrame:CGRectMake(187, 660, 400, 400) 
                 andOrderedItem:@"New" 
                   andTag:self.tagNumber 
                 withFoldArray:self.foldTypeArray 
                 withRollArray:self.rollTypeArray]; 

    cView.tag =self.tagNumber; 
    NSLog(@"Assigned tag is %d",cView.tag); 
    cView.delegate = self; 

    CGPoint scrollPoint = CGPointMake(0.0, (cView.frame.origin.y/500)*400); 
    [self.scrollView setContentOffset:scrollPoint animated:YES]; 

    [self.scrollView addSubview:cView]; 

    CGFloat scrollViewHeight = 0.0f; 
    for (UIView *view in self.scrollView.subviews) 
    { 
     scrollViewHeight += view.frame.size.height; 
    } 

    CGSize newSize = CGSizeMake(320,scrollViewHeight); 
    //CGRect newFrame = (CGRect){CGPointZero,newSize}; 
    [self.scrollView setContentSize:newSize]; 
    NSLog(@"the scroll view height is %f",scrollViewHeight); 
    self.currentCGRectLocation = cView.frame; 

    for (NSObject *newObj in cView.subviews) 
    { 
     if ([newObj isMemberOfClass:[UITextField class]]) 
     { 
      UITextField *txtObj = (UITextField *)newObj; 
      switch (txtObj.tag) { 
       case 6: //Length 
        NSLog(@"6 item value is %@",txtObj.text); 
        txtObj.text = [soliI.length stringValue]; //[NSString stringWithFormat:@"%1.1f",length]; 
        break; 
       case 7: //Width 
        NSLog(@"7 item value is %@",txtObj.text); 
        txtObj.text = [soliI.width stringValue]; //[NSString stringWithFormat:@"%1.1f",width]; 
        break; 

       default: 
        break; 
      } 
     } 
     else if ([newObj isMemberOfClass:[UITextView class]]) 
     { 
      UITextView *txtView = (UITextView *)newObj; 
      NSLog(@"the tag is %d",txtView.tag); 
      if (txtView.tag == 17) 
      { 
       txtView.text = soliI.specialInstructions; 
      } 
     } 
     else if ([newObj isKindOfClass:[UIButton class]]) 
     { 
      UIButton *btn = (UIButton *)newObj; 
      NSLog(@"btn tag is %d",btn.tag); 
      switch (btn.tag) { 
       case 12: 
        [btn setTitle:@"Fold" forState:UIControlStateNormal]; 
        break; 
       case 13: 
        [btn setTitle:@"Roll" forState:UIControlStateNormal]; 
        break; 
       default: 
        break; 
      } 
} 
+0

爲什麼您的scrollView的contentView大小與cView的框架大小相同? – codingNinja

回答

0

我不知道你的代碼,什麼是真正happening.But的事情是,滾動型的contentSize需要兩個PARAM,要滾動,因爲它是CGSize的性質,即高度和寬度,不像CGRectMake如你所用。

選中此項,可能會排序您的概率。

+0

增加了一些代碼。請檢查一下。它仍然不起作用。我改變它將滾動視圖大小設置爲CGSize。 – RookieAppler