以下を含む非常に単純な ViewController があります。
@interface ServingsView : UIViewController
@property (retain, nonatomic) IBOutlet UILabel *labelTitle;
@property (retain, nonatomic) IBOutlet UILabel *labelContent;
@property (retain, nonatomic) IBOutlet UIButton *buttonSelect;
このコントローラーの m ファイルにコードを追加しませんでした。
今、私はこのビューコントローラーを作成し、そのビューをスクロールビューに追加しています:
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];
}
今、あとがきのどこにも ChoiceView を使用していません。何が起こっているのかというと、ボタンは表示されておらず、そのビューはまったく応答していません。その環境でビューを使用してスクロールすると、さまざまな種類の例外が発生します。CALayer 例外の場合もあれば、stView 例外の場合もあります。リリース行を削除すると、すべて正常に動作します。
そこでは起こらなかったテストプロジェクトを作成したので、ここに何かが欠けています。