爲什麼下面不顯示正確的UITableView附件視圖?它只是顯示在nib文件中選擇的UIAcessoryTypeCheckmark。UITableView附件查看未顯示
- (UITableViewCell *)tableView:(UITableView *)tableView cellForManagedObject:(NSManagedObject *)managedObject withIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Selection";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil) {
cell = tvCell;
self.tvCell = nil;
}
self.tableView.rowHeight = 70.0f;
//Background
BOOL useDarkBackground = NO; //odd
if(indexPath.row %2 == 0) useDarkBackground = YES; //even
NSString *backgroundImagePath = [[NSBundle mainBundle] pathForResource:useDarkBackground ? @"DarkBackground" : @"LightBackground" ofType:@"png"];
UIImage *backgroundImage = [[UIImage imageWithContentsOfFile:backgroundImagePath] stretchableImageWithLeftCapWidth:0.0 topCapHeight:1.0];
cell.backgroundView = [[[UIImageView alloc] initWithImage:backgroundImage] autorelease];
cell.backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
cell.backgroundView.frame = cell.bounds;
//Checkmark
cell.userInteractionEnabled = YES;
NSString *checkmarkImagePath;
checkmarkImagePath = [[NSBundle mainBundle] pathForResource:[selectedObjects containsObject:managedObject] ? @"checkSelected" : @"checkUnselected" ofType:@"png"];
if([selectedObjects count] == 0) {
checkmarkImagePath = [[NSBundle mainBundle] pathForResource:@"checkUnselected" ofType:@"png"];
}
UIImage *checkmarkImage = [[UIImage imageWithContentsOfFile:checkmarkImagePath] stretchableImageWithLeftCapWidth:0.0 topCapHeight:1.0];
UIImageView *imageView = [[[UIImageView alloc] initWithImage:checkmarkImage] autorelease];
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.frame = CGRectMake(10.0, 10.0, imageView.frame.size.width/1.2, imageView.frame.size.height/1.2);
return cell;
}
出於某種原因,下面確實工作:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSManagedObject *objectToChange = [[self fetchedResultsControllerForTableView:tableView] objectAtIndexPath:indexPath]; //The object
[tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:NO];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
NSString *checkmarkImagePath = [[NSBundle mainBundle] pathForResource:[selectedObjects containsObject:objectToChange] ? @"checkSelected" : @"checkUnselected" ofType:@"png"];
UIImage *checkmarkImage = [[UIImage imageWithContentsOfFile:checkmarkImagePath] stretchableImageWithLeftCapWidth:0.0 topCapHeight:1.0];
UIImageView *imageView = [[[UIImageView alloc] initWithImage:checkmarkImage] autorelease];
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.frame = CGRectMake(10.0, 10.0, imageView.frame.size.width/1.2, imageView.frame.size.height/1.2);
cell.accessoryView = imageView;
}
非常感謝!
我知道我有很多內存泄漏。我知道要修復什麼,並且一旦我真正擁有了一些可行的東西,就會修復它 – joshim5 2011-06-02 16:27:17
@ joshim5 - 你沒有問過,但我要評論 - 它會很好地幫助你早日寫出你的習慣代碼沒有內存泄漏的地方。很快你就不必考慮這個問題了,而且你也不需要修復泄漏到生產代碼中的泄漏。我的2美分。 – Rayfleck 2011-07-15 22:04:29