2

奇妙な問題があります。

UIViewController をサブクラス化し、UITableView をロードする tableView プロパティを追加しています。今、この UITableView を親のサブビューに追加しています。正常に動作しますが、2 つの TableView が表示されます。1 つは標準スタイルの TableView で、もう 1 つは標準スタイルの上に配置したい方法です。ただし、どちらにも正しいデータが含まれています。

@interface RootViewController : UIViewController <ABPersonViewControllerDelegate, 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

- - - 更新しました - - -

一部だけ貼り間違えました

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

実際にはコードにあります

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

-------更新2--------

独自の UITableView を作成しない場合

tableView = [[UITableView alloc] ...]

次に、自動的に設定されたものがあります。これは私にとっては問題ありません...初期化する必要はありませんが、標準のフレームを変更することはできません。

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

フレームを設定しても何の効果もありません...

4

3 に答える 3

1

私はおそらくUITableViewControllerをUIViewControllerに変換しているのと同じ問題があり、RootViewControllerにuitableviewがある可能性があります。

IBOutlet で RootviewController の _tableview のプロパティを作成します。そして、それを XIB の tableview にリンクします。

RootviewController に _tableview を割り当てず、addsubview を追加しないでください。

于 2012-05-24T06:08:06.783 に答える
0

これの代わりに、

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

使用してみましたか:

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

なぜそうなるのかわかりませんが、目立つのはそれだけです。また、IBで別のUITableViewが設定されていないことを確認してください。

また、toolbarControllerと関係があるかもしれません。カスタムクラスだと思いますので、その中でUITableViewを作成していないことを確認してください。

于 2010-03-18T16:44:18.417 に答える
0

私は同じ問題に遭遇しました...

テーブルビューをView Controllerに直接追加する代わりに([self.parentViewController.view addSubview:tableView];)、次の方法を使用してください..

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

これで修正されることを願っています(@krisも!)

于 2011-12-28T12:19:58.487 に答える