7

私はいたるところにいますがUITableView、静的な背景の問題は十分に文書化されているようですが、簡単な解決策を持っている人は誰もいませんか?TableViews私は次のように完全にコードで構築しています:

    UIViewController *tableViewController = [[TableViewController alloc] init];
navigationController = [[UINavigationController alloc]
                        initWithRootViewController:tableViewController];
[tableViewController release];
[window addSubview:navigationController.view];

ウィンドウはUIWindow、アプリデリゲートでの私のメインビルドです。ここからは、いくつかの異なるTableViews(によって制御されるnavigationController)を構築する必要があります。いくつかはfetchedResultsControllers、カスタムセルなどを使用します。私はこれを完全にコードで行うことを好みます。これは、コードとIBの間でカスタマイズが広がるか、6つ以上の異なるNibをビルドして維持する必要があるため、nibを使用しないでください。

tableViewControllerクラスが独自の背景画像を設定する実際の例を見つけることができません。TableViews私の(拡張)の1つでこれを行う場合UITableViewController

self.tableView.backgroundColor = backgroundColor;

もちろん、tableViewの背景に色を付けます(これは偶然にもセルにも色を付けますが、セルは?から色を継承していると思いtableViewます)が、セルが上下にスライドする静的な背景画像が必要です。ユーザーのジェスチャーで上下にスライドする「背景画像」ではありません。GroupedStyle tableViewが提供するものとまったく同じですが、PlainStyle tableView :) ..であり、IBではなくコードを使用して実行されます。

テーブルビューの背景色をクリアしてから、セルの色を設定して、透明にならないようにする必要があると思います。そして、どういうわけか、tableViewインスタンス内からtableViewビューの下の背景画像を「こっそり」しますか?

これをどのように行うか、最善の解決策は、viewDidLoadまたはTableViewController内の他の関数でこれを実行して、すべてのカスタマイズを1か所に保持できるようにすることです。

誰かが私を助けてくれることを願っています、私はすべて'グーグルアウト':)ありがとう!

4

5 に答える 5

9

UIViewControllerコントローラを。ではなく、として設定する必要がありますUITableViewControllertableview次に、プログラムで背景の上に追加しますimageView

@interface SomeController : UIViewController <UITableViewDataSource, UITableViewDelegate> {
  ...
  UITableView *tableView;
  ...
}
@property (nonatomic, retain) UITableView *tableView;
@end



@implementation SomeController

@synthesize tableView;

...

- (void)loadView {
    [super loadView];
    UIImageView *v = [[[UIImageView alloc] initWithFrame:self.view.bounds] autorelease];
    [v setImage:[UIImage imageNamed:@"table_background.png"]];
    [self.view addSubview:v];


    self.tableView = [[[UITableView alloc] initWithFrame:self.view.bounds] autorelease];
    [self.tableView setBackgroundColor:[UIColor clearColor]];
    [self.view addSubview:self.tableView];
}
...
@end
于 2009-10-28T15:05:31.360 に答える
6

> iOS 3.2をターゲットにしている場合、このジャンプスルーはすべて不要です。iOS3.2では、新しいbackgroundViewプロパティを使用してUIImageViewを直接設定できます。例:

// In your UITableViewController subclass
- (void)viewDidLoad
{
    [super viewDidLoad];

    UIImageView *view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.png"]];
    self.tableView.backgroundView = view;
}  
于 2012-04-14T12:07:00.013 に答える
2

これで実行中です:)tableViewにセルが入力されていないため、TableViewDataSourceとTableViewDelegateを実装したにもかかわらず、これはメインビューにのみ存在することがわかったので、ブレークポイントを設定する必要がありました。デリゲートを設定する必要がありました。テーブルビューのデータソースを=selfにします。これに対する答えを探している他の人にとっては、Coneybearesの助けを借りて終わった方法です:

- (void)loadView {
[super loadView];

UIImageView *imageView = [[[UIImageView alloc] initWithFrame:self.view.bounds] autorelease];
[imageView setImage:[UIImage imageNamed:@"carbon_background.png"]];
[self.view addSubview:imageView];

[self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds] autorelease];
[self.tableView setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:self.tableView];

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

}

于 2009-10-28T19:33:22.367 に答える
0

Coneybeareに感謝します。

もうクラッシュせず、背景画像は(上部のnavigationControllerとともに)完璧に表示されますが、それでもtableViewは表示されませんか?背景画像とnavigationControllerBarのみ:

これは私の実装です:

- (void)loadView {
[super loadView];

UIImageView *imageView = [[[UIImageView alloc] initWithFrame:self.view.bounds] autorelease];
[imageView setImage:[UIImage imageNamed:@"carbon_background.png"]];
[self.view addSubview:imageView];

[self.tableView = [[UIView alloc] initWithFrame:self.view.bounds] autorelease];

[self.tableView setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:self.tableView];

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)theTableView {
return 1;

}

- (NSInteger)tableView:(UITableView *)theTableView numberOfRowsInSection:(NSInteger)section {
return 3;

}

- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [theTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = @"Hello, World";

return cell;

}

//編集、didSelectRow、メモリなどをコミットします。

フォーラムは、一度に.mファイル全体を処理することはできませんでした。エラーを示すのに役立つ可能性のあるものを省略した場合は、教えてください。

多分それはレイヤーの順序だと思い、運がなくてこれを試しました:

    [self.view sendSubviewToBack:imageView];

明らかな何かを見逃したことを願っています。

御時間ありがとうございます:)

于 2009-10-28T17:23:17.213 に答える
0

いくつかのヒント:

  • を使用する場合UISplitViewController

    splitViewController.view.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
    
  • を使用する場合UINavigationController

    navigationController.view.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
    
  • UISplitViewControlleraとaの両方を使用する場合UINavigationController

    navigationController.view.backgroundColor = [UIColor clearColor];
    splitViewController.view.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
    

またはUIViewの上にある、透けて見えるものの背景色を必ず設定してください。UINavigationControllerUISplitViewController[UIColor clearColor]

于 2012-03-04T21:37:28.047 に答える