0

適切なプロトコルを備えた MainWindowViewController があります。また、MainWindowViewController に実装された dataSouce メソッドもあります。

@interface MainWindowController : UIViewController < UITableViewDelegate, UITableViewDataSource, UAModalPanelDelegate, UIGestureRecognizerDelegate>

MainWindowViewController にデリゲートとデータソースを設定しましたviewDidLoad

self.friendsTableView.delegate = self;
self.friendsTableView.dataSource = self;

何が起こるかというと、友達ボタンを押すことです。FriendsPopUpView_iPhone という名前の xib ファイルが読み込まれ、複数UITableViewの友達が表示されます。しかし、friendsPopUpView のテーブルビューには空の行が表示されます。私は何を間違っていますか?

FriendsPopUpView_iPhone.xib にはUITableView. friendsTableView は、FriendsPopUpView_iPhone.xib で作成された tableview からのアウトレットです。friendsPopUpView は、UIViewFriendsPopUpView_iPhone.xib のビューのアウトレットです。メインの MainWindowController のフレンド ボタンに接続されたアクションを次に示します。

- (IBAction)on_friends:(id)sender {
    if (self.friendsPopUpView == nil) {
        [[NSBundle mainBundle] loadNibNamed:@"FriendsPopUpView_iPhone" owner:self options:nil];
        [self.view addSubview:self.friendsPopUpView];

        UIButton* clickedButton = (UIButton*) sender;
        CGRect sFrame = CGRectMake(clickedButton.frame.origin.x-100, clickedButton.frame.origin.y,
                                   self.friendsPopUpView.frame.size.width,
                                   self.friendsPopUpView.frame.size.height);
        self.friendsPopUpView.frame = sFrame;
    }
}
4

1 に答える 1

2

ポップアップ ビュー nib には、MainWindowViewController クラス (self.friendsPopUpView など) に接続されたアウトレットが含まれていますか? 何かが機能するためには、それが必要です。

テーブル ビューが存在する前にデリゲートとデータ ソースを設定することはできません。MainWindowViewController viewDidLoad が起動するときは存在しません。コードでデリゲートとデータソースをセットアップするには、nib がロードされた後、テーブルが存在するようにします。

他のアウトレット (friendsPopUp や friendsTableView など) を nib アウトレット (MainWindowViewController として設定した「ファイルの所有者」に接続) として設定すると、デリゲートとデータソースを同じ方法で設定でき、コードは必要ありません。それ以外の場合は、ペン先をロードした後にコードで実行します...

- (IBAction)on_friends:(id)sender {
    if (self.friendsPopUpView == nil) {
    [[NSBundle mainBundle] loadNibNamed:@"FriendsPopUpView_iPhone" owner:self options:nil];

    // assuming you have a friendsPopUpView outlet setup in the nib
    // also assuming you have a friendsTableView outlet setup in the nib, both of these connected

    // now this will work
    self.friendsTableView.delegate = self;
    self.friendsTableView.dataSource = self;
于 2013-03-28T02:16:53.023 に答える