2011-12-24 15 views
0

私は新しいプロジェクトを開始しました。私はARCを使用することを選択しましたが、かなり奇妙な問題があります。 私はUITableViewCellのサブクラスを持っています.UITableViewCellのサブクラスには、ユーザが長い間セルを押したかどうかに応じて2つのサイズがあります。 サイズが変更されると、実際のセルの背景と部分的に重なる異なる背景のセルの別の部分が表示されます。 これを行うには、プロパティ@property(強く、非原子的な、保持する)UIImageView * optionsImageView; 私は別のものを試しましたが、それらはすべて同じ結果につながるので、実際にコード化されたものについて説明します。 はinitメソッドで、IはoptionsImageViewを作成しflollowsとして自己に追加:ARCを使用しているポインタがありませんか?

UIImage* image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"sous_menu" ofType:@"png"]]; 
    self.optionsImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 
                      self.frame.size.height - 12, 
                      self.frame.size.width, 
                      image.size.height)]; 
    optionsImageView.backgroundColor = [UIColor clearColor]; 
    optionsImageView.image = image; 
    [self insertSubview:optionsImageView aboveSubview:self.backgroundView]; 
    optionsImageView.alpha = 0; 

ユーザが長いセルを押し、IはoptionsImageViewのアルファを変更します。 しかしlayoutSubviewsメソッドでそれを調べると、optionImageViewはnilなので、私のクラスの他のメンバーもそうです。あなたがshowOptionsPanelとHideOptionPanel、列挙型はlayoutSubviewsにしながらokですオプションでは、それはまだであることがわかります

#pragma mark - ACTIONS 
- (void)hideOptionsPanel 
{ 
    NSLog(@"hideOptionsPanel for %@", titleLabel.text); 
    self._cellOptions = LRCellOptionsHidden; 
    NSLog(@"_cellOptions %d", self._cellOptions); 
    self.optionsImageView.alpha = 0; 
} 

- (void)showOptionsPanel 
{ 
    NSLog(@"showOptionsPanel for %@", titleLabel.text); 
    self._cellOptions = LRCellOptionsShown; 
    NSLog(@"_cellOptions %d (optionsImageView %@)", self._cellOptions, optionsImageView); 
    self.optionsImageView.alpha = 1; 
} 

- (void)layoutSubviews 
{ 
    NSLog(@"layoutSubviews for %@ (%d)", titleLabel.text, self._cellOptions); 
    // rounded corners 
    self.icon.layer.cornerRadius = 5.0; 
    self.icon.clipsToBounds = YES; 
} 

、ここで、このすべてのためのouptputです....

2011-12-24 14:11:31.788 LendReminder[11189:fb03] layoutSubviews for Cars 2 Bluray (0) 
2011-12-24 14:11:32.137 LendReminder[11189:fb03] showOptionsPanel for Cars 2 Bluray 
2011-12-24 14:11:32.138 LendReminder[11189:fb03] _cellOptions 1 (optionsImageView (null)) 
2011-12-24 14:11:32.140 LendReminder[11189:fb03] layoutSubviews for Cars 2 Bluray (0) 
2011-12-24 14:11:32.141 LendReminder[11189:fb03] layoutSubviews for Cars 2 Bluray (0) 
2011-12-24 14:11:33.442 LendReminder[11189:fb03] layoutSubviews for Sleepy Hollow (0) 
2011-12-24 14:11:33.790 LendReminder[11189:fb03] hideOptionsPanel for Cars 2 Bluray 
2011-12-24 14:11:33.791 LendReminder[11189:fb03] _cellOptions 0 
2011-12-24 14:11:33.793 LendReminder[11189:fb03] showOptionsPanel for Sleepy Hollow 
2011-12-24 14:11:33.793 LendReminder[11189:fb03] _cellOptions 1 (optionsImageView (null)) 
2011-12-24 14:11:33.796 LendReminder[11189:fb03] layoutSubviews for Sleepy Hollow (0) 
2011-12-24 14:11:33.796 LendReminder[11189:fb03] layoutSubviews for Cars 2 Bluray (0) 
2011-12-24 14:11:33.797 LendReminder[11189:fb03] layoutSubviews for Sleepy Hollow (0) 

0に等しく、optionViewは無限です... 何ですか?これはARCと何か関係がありますか? Thx。

+1

-initメソッドがまったく呼び出されていますか? – diederikh

+0

はい、そうです。私が長い間セルを押すと、私はUIImageが現れるのを見て、すぐに消える...本当に変だ... – Khal

答えて

1

私はそれを得ました;)) xibにreuseIdentifierを設定しなかったので、cellAtIndexPathを呼び出すたびにセルが再構築され、したがってポインタはゼロになりました。 D:D:D

関連する問題