我有這個奇怪的問題。自定義的UITableViewCell與UIImageView不加載圖像的某些單元格
基本上我有一個UITableViewCell子類,它寫了一些插口並將其連接到筆尖。 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;
}
在其管理該小區的表格視圖的視圖控制器Cell.h
的子類
@property (weak, nonatomic) IBOutlet UIImageView *myImageView;
亞類中,
我已與所登記的筆尖使用以下代碼:
[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;
}
奇怪的是,說我有10個細胞中的區段2(如上),和我設置它們以相同的方式起作用,有些單元顯示齒輪圖標,有些則不顯示!滾動這些細胞進出視圖似乎改變哪些細胞顯示圖標,哪些沒有。
這意味着註冊單元格,包括設置重用標識符,在nib文件中設置子類,所有這些類型的東西都很好(常見的陷阱)。
這種行爲模式在我看來,與內存有關的 - 好像有什麼東西正在某處釋放...
下面是說明我的意思的圖片:
請幫幫我!
感謝
Vb的
編輯:
OK僅僅是明確的,沒有使用任何數據與此表IM,但儘管如此,有沒有原因,我那些嵌齒輪不該」不會出現!
- (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;
}
的輸出是...
我的觀點是,如果IM設置相同的圖像,其是在第二部分中的「設置」,爲什麼只有做的所有單元格其中一些有圖像顯示?
自定義Cell類:
@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設置爲零(如果沒有)。
只需對代碼中隱藏的問題發表評論即可,因爲Objective-C的最新版本不再需要* @ synthesize *。它會自動完成「_」約定 – rdurand 2013-03-27 16:52:34
謝謝,我刪除它! – Vazzyb 2013-03-27 16:58:51
看起來你每次都在'UITableView'數據源中傳遞'self.cogWheelImageForSettingsIcon',所以我不明白你有沒有可能讓每個單元格都沒有圖標圖像。 – RileyE 2013-03-27 17:27:29