Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在弹出子视图中拥有UITableView?_Ios_Objective C - Fatal编程技术网

Ios 如何在弹出子视图中拥有UITableView?

Ios 如何在弹出子视图中拥有UITableView?,ios,objective-c,Ios,Objective C,我有一个具有适当协议的MainWindowViewController。我还在MainWindowViewController中实现了dataSouce方法 @interface MainWindowController : UIViewController < UITableViewDelegate, UITableViewDataSource, UAModalPanelDelegate, UIGestureRecognizerDelegate> self.friendsTabl

我有一个具有适当协议的MainWindowViewController。我还在MainWindowViewController中实现了dataSouce方法

@interface MainWindowController : UIViewController < UITableViewDelegate, UITableViewDataSource, UAModalPanelDelegate, UIGestureRecognizerDelegate>
self.friendsTableView.delegate = self;
self.friendsTableView.dataSource = self;
- (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;
    }
}
应该发生的是我按下“朋友”按钮。加载了xib文件名FriendsPopUpView\u iPhone,它应该会显示朋友的
UITableView
。但是friendsPopUpView的tableview显示为空行。我做错了什么

FriendsPopUpView_iPhone.xib包含一个
UITableView
。 friendsTableView是在FriendsPopUpView_iPhone.xib中创建的tableview的一个出口。 friendsPopUpView是friendsPopUpView_iPhone.xib中视图的一个
UIView
插座。 以下是连接到MainWindowController上的friend按钮的操作

@interface MainWindowController : UIViewController < UITableViewDelegate, UITableViewDataSource, UAModalPanelDelegate, UIGestureRecognizerDelegate>
self.friendsTableView.delegate = self;
self.friendsTableView.dataSource = self;
- (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;
    }
}

弹出视图nib是否包含连接到MainWindowViewController类的插座(如self.friendsPopUpView)?为了使任何东西都能起作用,它必须是

在表视图存在之前,不能设置委托和数据源。当MainWindowViewController viewDidLoad启动时,它不存在。若要在代码中设置委托和数据源,请在加载nib后,在表存在后进行设置

如果您将其他出口(如friendsPopUp和friendsTableView)设置为nib出口(连接到“文件所有者”,您可以将其设置为MainWindowViewController),则可以以相同的方式设置委托和数据源,无需代码。否则,请在加载nib后在代码中执行

- (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;