开发者

UIViewController shows two UITableView

I have a weird problem.

I'm subclassing UIViewController and adding a tableView property in which I load a UITableView. Now I'm adding this UITableView to the parent's subviews. Works fine but I get TWO TableViews. One standard styled TableView and one the way I wanted it to be on top of the standard one. Both contain the correct data though.

@interface RootViewController : UIViewController <ABPersonViewControllerDelegate开发者_StackOverflow, UITableViewDelegate, UITableViewDataSource> {
  UITableView *tableView;
  ToolbarController *toolbar;
  ...
}

@property(nonatomic, retain) UITableView *tableView;
@property(nonatomic, retain) ToolbarController *toolbar;
...

@end

@implementation RootViewController
- (void)viewDidLoad {
  [super viewDidLoad];

  CGRect mainViewBounds = self.parentViewController.view.bounds;
  CGFloat toolbarHeight = 44;

  toolbar = [[ToolbarController alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(mainViewBounds), toolbarHeight) parentView:self]; 

  tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, toolbarHeight, CGRectGetWidth(mainViewBounds), CGRectGetHeight(mainViewBounds) - toolbarHeight) style:UITableViewStylePlain];
  tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
  tableView.rowHeight = 60.0;
  [tableView tableView].delegate = self;
  [tableView tableView].dataSource = self;
  tableView.backgroundColor = [UIColor clearColor];

  [self.parentViewController.view addSubview:tableView];
  [self.parentViewController.view addSubview:toolbar];
}
@end

------UPDATED------

I just wrongly pasted one part

[tableView tableView].delegate = self;
[tableView tableView].dataSource = self;

is actually in code

tableView.delegate = self;
tableView.dataSource = self;

-------UPDATE 2--------

If I don't create my own UITableView by

tableView = [[UITableView alloc] ...]

then there is one automatically set for me. This would be fine for me... I don't need to init one, but I can't change the frame on the standard one.

tableView.frame = CGRectMake(0, toolbarHeight, CGRectGetWidth(mainViewBounds), CGRectGetHeight(mainViewBounds) - toolbarHeight);

Setting frame has no effect whatsoever...


i Had the same issue you probably be converting the UITableViewController to UIViewController and Your RootViewController might have the uitableview.

Make the Property of _tableview in your RootviewController with IBOutlet. And link it with the tableview in your XIB .

Don't alloc _tableview in RootviewController and Don't addsubview it .


Instead of this,

[tableView tableView].delegate = self;
[tableView tableView].dataSource = self;

Have you tried just using:

tableView.delegate = self;
tableView.dataSource = self;

I don't know why it would be that, but it's the only thing that's standing out. Also make sure you haven't got another UITableView set up in IB.

It might also have something to do with toolbarController. I'm assuming it's a custom class, so make sure you're not creating a UITableView in that.


I ran into same issue...

Instead of adding tableview to the view controller directly ([self.parentViewController.view addSubview:tableView];), use following way..

UIView *totalView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
[totalView addSubview:tableView];
self.view=totalView;

Hope this fixes it (for @kris too!)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜