私はこの本当に奇妙な問題を抱えています。
基本的に、いくつかのアウトレットを書き、Nib にリンクした UITableViewCell サブクラスがあります。
Cell.h のサブクラス
@property (weak, nonatomic) IBOutlet UIImageView *myImageView;
Cell.m のサブクラス
@synthesize myImageView = _myImageView; // do i need this?
- (void) setUpCell... image:(UIImage*)image
{
if(image)
self.myImageView.image = image;
else
self.myImageView.image = nil;
}
セルのテーブルビューを管理するView Controllerで、
次のコードを使用して Nib に登録しました。
[self.tableView registerNib:[UINib nibWithNibName:pathToNibForBaseMenuCell bundle:nil] forCellReuseIdentifier:identifierForBaseMenuCell];
cellForRowAtIndexPath では、セルをデキューして画像を設定します...
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierForBaseMenuCell];
switch (indexPath.section) {
case 2:
[cell setUpCell...image:self.cogWheelImageForSettingsIcon];
break;
default:
break;
}
return cell;
}
奇妙なことに、セクション 2 (上記のように) に 10 個のセルがあり、それらを同じ方法で設定したとします。一部のセルには歯車アイコンが表示され、一部のセルには表示されません! これらのセルをスクロールして表示または非表示にすると、アイコンを表示するセルと表示しないセルが変わるようです。
これは、再利用識別子の設定、nib ファイルでのサブクラスの設定など、セルの登録はすべて問題ないことを意味します (一般的な落とし穴)。
この動作パターンは、メモリに関連しているように思えます-何かがどこかで割り当て解除されているかのように...
これが私が何を意味するかを説明するための写真です:
助けてください!
ありがとう
VB
編集:
明確にするために、私はまだこのテーブルでデータを使用していませんが、それにもかかわらず、これらの歯車が表示されない理由はありません!
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
switch (section) {
case 0:
return 1;
break;
case 1:
return 10;
break;
case 2:
return 10;
break;
default:
return 0;
break;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierForBaseMenuCell];
switch (indexPath.section) {
case 0:
[cell setUpCell... text:@"Username" image:nil];
break;
case 1:
[cell setUpCell... text:@"Magazine" image:nil];
break;
case 2:
{
NSString* str = [NSString stringWithFormat:@"Settings: %d",indexPath.row];
[cell setUpCell... text:str image:self.cogWheelImageForSettingsIcon];
break;
}
default:
break;
}
return cell;
}
その出力は...
私のポイントは、2番目のセクションの「設定」にあるすべてのセルに同じ画像を設定している場合、なぜそれらの一部だけに画像が表示されるのですか?
カスタム セル クラス:
@interface CustomCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UIImageView *backgroundImageView;
@property (weak, nonatomic) IBOutlet UILabel *mainLabel;
@property (weak, nonatomic) IBOutlet UILabel *arrowView;
@property (weak, nonatomic) IBOutlet UIImageView *myImageView;
- (void) setUpCelltext:(NSString*)text image:(UIImage*)image;
@implementation CustomCell
- (void) setUpCelltext:(NSString*)text image:(UIImage*)image
{
self.backgroundImageView.image = [UIImage imageNamed:pathForBackgroundImage];
self.myImageView.layer.cornerRadius = kCornerRadiusOfImageView;
self.myImageView.layer.masksToBounds = YES;
if(image)
self.myImageView.image = image;
else
self.myImageView.image = nil;
NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:self.fontForText forKey:NSFontAttributeName];
NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:text attributes:attrsDictionary];
self.mainLabel.attributedText = attrString;
}
@end
セルには、カスタム フォント、矢印ビュー、背景ビューがあります。これらはすべて正常に機能します。セクションによって変わります。うまくいかないイメージばかりです。cellForRowAtIndexPath によって呼び出されるこの関数は、提供されている場合は画像を設定し、提供されていない場合は imageview を nil に設定することがわかります。