2011-01-22 16 views
0

私のクラスには次のコードがあります。私はシミュレータ上で私のアプリを起動するときに動作します。しかし、実際のデバイス(iPhone 1g、3.1.3)でアプリを起動するときは機能しません。何か案は?UITableViewCell iPhoneの背景に関する問題

(それはグラデーションの背景を作るためだ)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
static NSString *MainScreenCellID = @"MainScreenCellID"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MainScreenCellID]; 

if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MainScreenCellID] autorelease]; 
} 

cell.textLabel.text = [[[self.controllers objectAtIndex:[indexPath row]] navigationItem] title]; 
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

UIImageView *bgimage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cell_bg.png"]]; 
cell.backgroundView = bgimage; 
[bgimage release]; 

for (UIView *view in cell.contentView.subviews) { 
    view.backgroundColor = [UIColor clearColor]; 
} 

return cell;  
} 

temp

(アプリがまだ行われていないので、黒フィールドが追加されます。)

EDIT:

私が追加することができますこのメソッドが動作するUITableViewCellで私自身のサブクラスを作成しましたが、ここではUITableViewDefaultStyleを使用していても動作しません。

+1

accessoryTypeやbackgroundViewのような静的プロパティの初期化では、if(cell == nill){...}に移動できます – Victor

答えて

6

clearColorを設定するための良い場所は、私はあなたにもcontentViewためclearColorを設定すべきだと思う

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { ... } 

です。

+0

ありがとう!これは、iOSのシミュレータやそれ以降のバージョンでも機能しますが、面白かったです。 forループを移動するだけで十分でした。 – LuckyLuke

関連する問題