Note that there are some explanatory texts on larger screens.

plurals
  1. POImage on uitableview lost after scrolling
    text
    copied!<p>in my application, i'm loading images to the cells of a table. But, when i scroll the table, the image goes out of sight of the table(goes up), it wont be there even if i scroll back.</p> <p>customCell.h</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface CustomCell : UITableViewCell&lt;UINavigationControllerDelegate, UIImagePickerControllerDelegate&gt; { UIViewController *viewController; UIImageView *imageView; UIButton *button; @property (nonatomic, retain) IBOutlet UIImageView *imageView; @property (nonatomic, assign)UIViewController *viewController; @property (nonatomic, retain) IBOutlet UIButton *button; -(IBAction)selectExistingPicture1; @end } </code></pre> <p>customCell.m</p> <pre><code> #import "CustomCell.h" @implementation CustomCell @synthesize imageView; @synthesize viewController; @synthesize button; - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { [picker dismissModalViewControllerAnimated:YES]; } - (IBAction)selectExistingPicture1 { if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary]) { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.delegate = self; picker.allowsImageEditing = YES; picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; [self.viewController presentModalViewController:picker animated:YES]; [picker release]; } else { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error accessing photo library" message:@"Device does not support a photo library" delegate:nil cancelButtonTitle:@"Drat!" otherButtonTitles:nil]; [alert show]; [alert release]; } } - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo { UIImage *thumbnail = [image _imageScaledToSize:CGSizeMake(80, 80) interpolationQuality:1]; /*CGSize newSize = CGSizeMake(80, 80); UIGraphicsBeginImageContext( newSize ); [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)]; UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();*/ imageView.image = thumbnail; [picker dismissModalViewControllerAnimated:YES]; } - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { // Initialization code } return self; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } - (void)dealloc { [imageView release]; [viewController release]; [button release]; [super dealloc]; } @end </code></pre> <p>cameraViewController.h</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface Camera1ViewController : UIViewController &lt;UITableViewDelegate,UITableViewDataSource&gt; { } @end </code></pre> <p>cameraViewController.m</p> <pre><code>#import "Camera1ViewController.h" #import "CustomCell.h" @implementation Camera1ViewController - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (void)dealloc { [i [super dealloc]; } #pragma mark Table Data Source Methods - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 25; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CustomCellIdentifier = @"CustomCellIdentifier"; CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CustomCellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CustomCellIdentifier] autorelease]; NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil]; for (id currentObject in nib){ if ([currentObject isKindOfClass:[CustomCell class]]){ cell = (CustomCell *)currentObject; cell.viewController = self; break; } } } //dont know what to do here. return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 100; } - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { NSString *key = @"Album"; return key; } @end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload