2011-12-06 12 views
3

グループ化されたUITableViewの背後にビューを追加しようとしています。残念ながら、私がスクロールするたびに、バックグラウンドビューも動きます。これは[self.view insertSubview:backgroundView belowSubview:_tableView]、または[_tableView setBackgroundView:backgroundView]を使用しても発生します。この背景ビューがスクロールする理由は何ですか?また、私はなぜスクロールを無効にしても、私のtableViewスクロールはしますか?これらは関連していますか? history.mでUITableViewで固定の背景ビューを作成するには?

History *historyController = [[History alloc] init]; 
    UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:historyController]; 

:アプリのデリゲートで

あなたのコントローラがUITableViewControllerだけtableViewUIViewController<UITableViewDelegate, UITableViewDatasource>に変更している場合

- (void)viewDidLoad { 

    CGRect frame = self.view.frame; 
    frame.origin.x = 0; 
    frame.origin.y = 0; 
    _tableView = [[UITableView alloc] initWithFrame:frame style:UITableViewStyleGrouped]; 
    _tableView.delegate = self; 
    _tableView.dataSource = self; 
    [_tableView setScrollEnabled:NO]; 
    [_tableView setBackgroundColor:[UIColor clearColor]]; 
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; 

    UIView *bg = [[UIView alloc] initWithFrame:frame]; 
    [bg setBackgroundColor:[UIColor scrollViewTexturedBackgroundColor]]; 
    UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"CenterFade.png"]]; 
    iv.alpha = .750; 
    [bg addSubview:iv]; 
    [iv release]; iv = nil; 

    [self.view addSubview:bg]; 
    [self.view addSubview:_tableView]; 
    [bg release]; bg = nil; 
    [_tableView release]; 

    [super viewDidLoad]; 
} 

答えて

1

なぜこれが起こっているのか分かりませんが、何らかの理由でself.viewがUITableViewであり、UIViewではありません。新しいUIViewを作成し、それをself.viewに設定すると問題は解決しました。私はUITableViewControllerを使用していませんが、UIViewControllerです。 UITableViewがどこから来ているのか分かりません!

+0

私はシミュレータからアプリケーションを削除してしまいました。そして、私が再び走ったとき、この問題はなくなりました。繰り返しクリーニングや再構築にもかかわらず、何かが更新されていないようなバグだったようです。 (私はUITableViewControllerからUIViewControllerに変更しました)。 – arsenius

1

- (void)viewDidLoad { 

    CGRect frame = self.view.frame; 
    frame.origin.x = 0; 
    frame.origin.y = 0; 

    UIView *bg = [[UIView alloc] initWithFrame:frame]; 
    [bg setBackgroundColor:[UIColor scrollViewTexturedBackgroundColor]]; 
    UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"CenterFade.png"]]; 
    iv.alpha = .750; 
    [bg addSubview:iv]; 
    [iv release]; 
    iv = nil; 

    _tableView = [[UITableView alloc] initWithFrame:frame style:UITableViewStyleGrouped]; 
    _tableView.delegate = self; 
    _tableView.dataSource = self; 
    [_tableView setScrollEnabled:NO]; 
    [_tableView setBackgroundColor:[UIColor clearColor]]; 
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; 

    [bg addSubview:_tableView]; 
    [_tableView release]; 
    _tableView = nil; 
    [self.view addSubview:bg]; 
    [bg release]; 
    bg = nil; 

    [super viewDidLoad]; 
} 

をお試しくださいプロパティ(それは同じです)

+0

をスクロールするとき、私は全く理由を理解するが、それでも追加した後にしていない移動されません背景ビューへのテーブルビュー、背景ビューはまだ上下にスクロールしています。これは私をナッツにしている! – arsenius

1

[_tableView setBackgroundColor:[UIColor clearColor]];

を設定し、その後のUIViewControllerのビュー階層でのUITableViewの下であなたの背景ビューを置きます。

+0

私はパターンに背景色を設定しているので動作しません(しかし、私は第3のビューを使用してその上に背景パターンを設定することができました)。また、それはすでにUITableViewの下にあります。とにかく背景にクリアな背景色を設定する必要があるのはなぜですか? – arsenius

+0

テーブル背景パターンを任意のビュー背景に設定できます。テーブルに透明な背景がある場合は、その下に任意のビューとコントロールを自由に描画できます。私はそれが理由であるとは思わないが、必要ならば買うことができる。 –

0

UITableViewは、backgroundViewの特性を有する。

スウィフト:

var backgroundView: UIView? 

のObjective-C

@property(nonatomic, readwrite, retain) UIView *backgroundView 

このビューは、あなたがのtableView

関連する問題