사용자 지정 배경 이미지가 포함 된 iPhone uitable view plainstyle- 코드에서 "완전히"완료되었습니다.

StackOverflow https://stackoverflow.com/questions/1637738

문제

나는 모든 곳에 있었는데 UITableView 정적 배경 문제는 잘 문서화되어 있지만 간단한 솔루션을 가진 사람은 없습니까? Im Building My TableViews 다음과 같이 전적으로 코드로 :

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

창문이 내 메인입니다 UIWindow 앱 대의원에서 나를 위해 빌드하십시오. 여기에서 나는 몇 가지 다른 것을 만들어야합니다. TableViews (제어 navigationController), 일부는 fetchedResultsControllers, 맞춤 셀 등. Code와 IB 사이에 사용자 정의 스프레드가 발생하거나 6 개 이상의 다른 펜촉을 빌드하고 유지 해야하는 NIB를 사용하지 않고 코드로 완전히 수행하는 것이 좋습니다.

나는 단순히 작동 예를 찾을 수 없다 tableViewController 클래스는 자체 배경 이미지입니다. 내가 이것을 내 안에서한다면 TableViews (확장 UITableViewController):

self.tableView.backgroundColor = backgroundColor;

물론, TableView의 배경색을 얻습니다 (우연히 셀을 색칠하는 것은 셀의 색상을 tableView?) 그러나 나는 내 셀이 위아래로 미끄러지는 정적 배경 이미지를 원한다. 사용자 제스처와 함께 위아래로 미끄러지는 "배경 이미지"가 아닙니다. GroupedStyle TableView가 제공하는 내용이지만 일반 스타일 테이블 뷰에서 제공하는 것과 IB가 아닌 코드를 사용하여 수행합니다.

테이블 뷰의 배경색을 지우고 셀 색상을 구성 할 때 셀 색상을 설정하여 투명하지 않도록해야한다고 생각합니다. 그런 다음 어떻게 든 테이블 뷰 인스턴스 내부에서 테이블 뷰보기 아래의 배경 이미지를 "몰래"?

어떻게이를 수행 할 것인가, 최상의 솔루션은 ViewDidload 또는 TableViewController 내부의 다른 기능에서 모든 사용자 정의를 한 곳에 유지할 수있는 방법으로이를 수행 할 수 있습니다.

누군가가 나를 도울 수 있기를 바랍니다. 모두 'googled out':) 감사합니다!

도움이 되었습니까?

해결책

컨트롤러를 설정해야합니다 UIViewController, UITableViewController. 그런 다음 추가하십시오 tableview 프로그래밍 방식으로 배경 위 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

다른 팁

당신이 대상을하고 있다면> iOS 3.2, 새로운 것을 사용할 수있는 경우, 후프를 통과하는이 모든 점프는 불필요합니다. 배경 뷰 uiimageview를 직접 설정하는 속성 : 예 :

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

    UIImageView *view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.png"]];
    self.tableView.backgroundView = view;
}  

자, 이제 실행 중입니다 :) 내 테이블 뷰는 내 셀로 채워지지 않았으므로 테이블 뷰드 다타 소스와 테이블 뷰드 elegate를 구현했지만 이것은 메인 뷰에서만 틀려서 대표를 설정해야한다는 것을 알게되었습니다. 그리고 테이블 뷰의 데이터 소스 = 자기. 여기에 대한 답을 찾는 다른 사람들에게는 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;

}

Coneybeare에게 감사합니다.

더 이상 충돌하지 않고 배경 이미지가 완벽하게 나타납니다 (맨 위에 내비게이션 콘트롤러와 함께) 여전히 보이는 테이블 뷰가 없습니까? 배경 이미지와 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;

}

// commit edit, didselectrow, memory… 등

포럼은 한 번에 전체 .M 파일에 대한 것이 아닙니다. 오류를 나타내는 데 도움이 될 수있는 무언가를 남겼는지 알려주세요.

나는 그것이 레이어의 순서라고 생각했고 운이없는 일을 시도했다.

    [self.view sendSubviewToBack:imageView];

내가 분명한 것을 놓쳤 으면 좋겠다.

시간 내 줘서 고마워:)

몇 가지 팁 :

  • A를 사용하는 경우 UISplitViewController:

    splitViewController.view.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
    
  • A를 사용하는 경우 UINavigationController:

    navigationController.view.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
    
  • 두 가지를 모두 사용하는 경우 UISplitViewController 그리고 a UINavigationController:

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

어떤 배경색을 설정하십시오 UIView 당신은 그것을 통해보고 싶어 UINavigationController 또는 UISplitViewController 에게 [UIColor clearColor].

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top