本当に面倒ですが、何らかの理由で自分のImageViewがセルビューのすぐ後ろに表示されます。クリッピングをオフにすると、画像がセルのすぐ後ろに表示されます。参考までに、写真ライブラリから選択してPNGに変換した画像を表示しようとしています。UITableViewCell:画像はCellビューの後ろに表示されます
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *headerCellID = @"FormHeaderCellView";
if(indexPath.section==0 && indexPath.row==0) //Header cell
{
FormHeaderCellView *cell = (FormHeaderCellView *)[self.tableView dequeueReusableCellWithIdentifier:headerCellID];
if (cell == nil)
{
NSArray *topLevelObjects =[[NSBundle mainBundle] loadNibNamed:headerCellID owner:nil options:nil];
for (id currentObject in topLevelObjects)
{
if([currentObject isKindOfClass:[UITableViewCell class]])
{
cell = (FormHeaderCellView *) currentObject;
break;
}
}
}
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *file = [documentsDirectory stringByAppendingPathComponent:@"logo.png"];
if([[NSFileManager defaultManager] fileExistsAtPath:file])
{
UIImage *img=[[UIImage alloc] initWithContentsOfFile:file];
[cell.logoImage setImage:img];
}
[cell.textLabel setText:[[NSUserDefaults standardUserDefaults] objectForKey:@"userName"]];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
return cell;
}
私は視覚的に細胞の背後の画像を見ることができるので、すべてがうまく読み込まれているようです。 あなたの助けに感謝します。
更新:いくつかのテストを行なったし、ペン先に私がバンドル内の任意の画像に logoImageのイメージプロパティを設定した場合、画像がうまく表示されます。だから問題は、ドキュメントディレクトリ(写真ライブラリから保存されたもの)から読み込まれたイメージを表示することです。
ここで、frame.logoImageのフレームを作成していますか? –
FormHeaderCellViewはUITableViewCellのサブクラスで、logoImageはIBOutlet UIImageViewプロパティです。 NIBで私は接続をちょうどうまく接続している。 – jAmi
NIBで、logoImageが他のすべての上にあることを確認してください。 –