3

これが私のシナリオです:

Main VC : Scroll View : [Multiple] MyPage : [Multiple] ObjectView : [Multple] UIButton

を含むメイン ビュー コントローラーがありUIScrollViewます。Scroll ビューはMyPage、pagingEnabled で複数の " " ビューをロードすることになっています。IB を使用して " MyPage" インターフェイス ( MyPage.xib) とビュー コントローラー ファイル ( MyPage.h &.m) を作成します。 MyPage.xibファイルの所有者は MyPage に設定されます。この " " は、IB を使用して ( 、、)MyPageで作成した複数の ObjectView を再びロードします。ObjectView.xibObjectView.hObjectView.m

MyPage クラスと ObjectView クラスはどちらも、データ プロパティの一部を保持する UIViewController のサブクラスです。

ObjectView クラスにはいくつかのボタンがあり、それらのボタン Touch Up アクションを制御によって接続し、ボタンを ObjectView.h にドラッグします。

私のメイン VC の viewDidLoad メソッドには、すべてのページを追加するループがあります。

- (void)viewDidLoad {
  ...
  for (int i=0; i<numPages; i=i+1) {
    MyPage *spg =[[MyPage alloc]i init];
    ...definition of spg properties...
    [spg loadPage:i+1];
    [scrollView addSubview:spg.view];
  }
}

MyPage の loadPage メソッドには、すべての ObjectView を追加するループがあります。

- (void) loadPage:(int) x {
  ...
  for (int i=0; i<numObjects; i++) {
    ObjectView *objvc = [[ObjectView alloc] init];
    ... defining objvc frame coordinates && other properties ...
    [self.view addSubview:objvc.view];
  }
}

ObjectView にはいくつかのボタンがあり、Ctrl キーを押しながらボタンを ObjectView.h にドラッグすることで、これらのボタンを IB の TouchUp アクションに接続します。

アプリが正常にビルドされ、スクロール ビューが読み込まれ、すべてのページとすべてのオブジェクトが適切に表示されます。ただし、ボタンに触れると、次の実行時エラーが表示されます。

キャッチされない例外「NSInvalidArgumentException」が原因でアプリを終了しています。理由:

-[TitleLayouer touchBtnOnline:]: インスタンス 0x17f810 に送信された認識されないセレクター

ボタン アクション メソッドの最初のステートメントにブレーク ポイントを設定しようとしましたが、そのブレーク ポイントに到達することさえできません。

誰かがこの問題で私を助けてくれることを願っています。

4

2 に答える 2

1

I find out the problem and solution. The problem is due to ARC releasing the ObjectView and MyPage object when they are outside their scope (the loop?), so in run-time it cannot reference to the View Controller objects in memory anymore.

The solution is to have a NSMutableArray property in the View Controller (and remember to alloc it with init, I once forgot about it and it causes another memory error...). Inside the loop, add the view controller objects (ObjectView/MyPage) to the array so these objects will be retained in the memory.

于 2012-09-10T07:55:17.463 に答える
0

メソッド touchBtnOnline: を .m ファイルで定義していないと思います。

于 2012-09-10T07:39:26.723 に答える