Search code examples
iosuiviewcontrollerreleaseaddsubview

viewcontroller release causes crashes or strange phenomenons


I have a very simple ViewController that contains the following:

@interface ServingsView : UIViewController
@property (retain, nonatomic) IBOutlet UILabel *labelTitle;
@property (retain, nonatomic) IBOutlet UILabel *labelContent;
@property (retain, nonatomic) IBOutlet UIButton *buttonSelect;

I added no code to the m file of this controller.

Now, I'm creating this viewcontroller and add its view to a scroll view:

 for (NSSubArray * Choice in currentItem.ItemsArray)
    {
        stView * ChoiceView=[[stView alloc]initWithNibName:@"stView" bundle:nil];
        ChoiceView.view.tag=1515;
        [mScrollView addSubview:ChoiceView.view];
        ChoiceView.view.frame=CGRectMake(0, [self getMinimumHeight]+h*ChoiceView.view.frame.size.height , 320, ChoiceView.view.frame.size.height);
        ChoiceView.labelTitle.text=Choice.ArrayName;

        [ChoiceView.buttonSelect addTarget:self action:@selector(onSubservingItemClicked:) forControlEvents:UIControlEventTouchUpInside];

        ChoiceView.buttonSelect.tag=h;
        h++;
        increaseHeight+=ChoiceView.view.frame.size.height;
        // here is the problem:
        [ChoiceView release];
    }

now, I'm not using ChoiceView anywhere afterwords. Whats going on is, that the button is not even shown and that view has no response what so ever. when using the views in its environment to scroll I'm getting different kind of exceptions. sometimes its CALayer exception, sometimes stView exception. when I'm removing the release line, everything is working fine.

I have even created a test project it didn't happen there, so I'm missing something here.


Solution

  • OK, this is the very strange answer! After many tests and a mock up application that failed to raise this error, I added the faulty controller to another application. Got the same results! So, I have deleted it entirely and create a new one... Now it's working.

    Apple - go figure...