表视图没有弹出

时间:2013-10-12 02:53:53

标签: iphone ios objective-c uitableview tableview

我在我的SideBarViewController的类xib文件中有这个TableViewController(IBOutlet sideTable挂钩的界面构建器对象),我试图在我的ViewController中填充(有点像Facebook的App侧菜单)。出于某种原因,我不能让这个工作。如果我将SideBarViewController类作为tableviewcontroller的子类并在其实现文件中逐步自定义tableview,它工作正常。但我宁愿使用xib。任何提示将不胜感激。

ViewController.h

      @property (nonatomic, strong) SidebarViewController *leftSidebarViewController;

ViewController.m

  - (UIView *)viewForLeftSidebar {
// Use applicationViewFrame to get the correctly calculated view's frame
// for use as a reference to our sidebar's view
CGRect viewFrame = self.navigationController.applicationViewFrame;
UITableViewController *controller = self.leftSidebarViewController.sideTable;
controller.view.frame = CGRectMake(0, viewFrame.origin.y, 270, viewFrame.size.height);
controller.view.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight;
return controller.view;
 }

SideBarViewController.h

      @property (nonatomic, strong) IBOutlet UITableViewController  *sideTable;

1 个答案:

答案 0 :(得分:0)

尝试以下步骤

1)更改SidebarViewController.h,使其看起来像

@interface SideBarViewController : UIViewController <UITableViewDataSource ,     
 UITableViewDelegate>
@property(nonatomic , weak) IBOutlet UITableView *sideTable;

2)在SideBarViewController.xib中,SideBarViewControllerUIView的挂钩视图。视图不应与UITableView挂钩。对于tableView,请使用与步骤(1)中相同的单独插座。

3)您的方法viewForLeftSideBar看起来像

- (UIView *)viewForLeftSidebar {
CGRect viewFrame = self.navigationController.applicationViewFrame;
// Assuming that self.leftSidebarController is already initialized up above.
if(self.leftSidebarViewController == nil){
self.leftSidebarViewController = [[SideBarViewController alloc] initWithNibName:@"SideBarViewController" bundle:nil];
}

self.leftSidebarViewController.view.frame = CGRectMake(0, viewFrame.origin.y, 270, viewFrame.size.height);
self.leftSidebarViewController.view.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight;
return self.leftSidebarViewController.view;
 }

我希望它会帮助你。