0

我正在动态添加一个自定义视图,我得到了这个异常

例外: ; 符号存根: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 =@"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;*/

上面有很多代码,我在 /* */ 中评论过。在此之前我也有一行

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

如果我取消注释上面的行,它就会开始出现异常。我在我的应用程序中的另一个地方看到了这段代码。当我第一次启动应用程序时,会调用此代码并且它工作正常。现在我将记录保存在此屏幕-A 上并进行其他计算(基本上转到另一个屏幕-B)并返回此屏幕并检索保存的记录并显示它,只需将其显示在屏幕 A 上然后我得到这个例外。我注意到的是我对滚动视图所做的任何事情都给出了例外。如果我省略这条线

[self.scrollView addSubview:cView];

在评论之外,我可以看到自定义视图添加得非常好..但我失去了滚动..屏幕卡住了..所以我认为问题与滚动视图有关。如果您需要更多信息,请告诉我。谢谢..

编辑:改为这个..仍然不起作用。

        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;
            }
}
4

1 回答 1

0

我不确定你的代码,到底发生了什么。但问题是 ScrollView 的 contentSize 需要两个参数,即你想要滚动的高度和宽度,因为它是 CGSize 的性质,与你使用的 CGRectMake 不同。

检查这个,可能它会排序你的概率。

于 2012-12-22T04:31:48.997 回答