Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>This answer is about how to retrieve images from documents directory and displaying them to UITableView...</strong>..</p> <p>first of all you have to get all images from your documents directory to an array....</p> <pre><code>-(void)viewWillAppear:(BOOL)animated { arrayOfImages = [[NSMutableArray alloc]init]; NSError *error = nil; NSString *stringPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0]; NSArray *filePathsArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath: stringPath  error:&amp;error]; for(int i=0;i&lt;[filePathsArray count];i++) { NSString *strFilePath = [filePathsArray objectAtIndex:i]; if ([[strFilePath pathExtension] isEqualToString:@"jpg"] || [[strFilePath pathExtension] isEqualToString:@"png"] || [[strFilePath pathExtension] isEqualToString:@"PNG"]) { NSString *imagePath = [[stringPath stringByAppendingString:@"/"] stringByAppendingString:strFilePath]; NSData *data = [NSData dataWithContentsOfFile:imagePath]; if(data) { UIImage *image = [UIImage imageWithData:data]; [arrayOfImages addObject:image]; } } } } </code></pre> <p>after that - using this array you can show the image in uitableview cell remember dont add the table view on your view untill your array is fill.....</p> <pre><code>#pragma mark - UItableViewDelegate methods -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [arrayOfImages count]; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tablView dequeueReusableCellWithIdentifier:CellIdentifier]; if(cell == nil) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } //adjust your imageview frame according to you UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0.0, 0.0, 470.0, 80.0)]; [imageView setImage:[arrayOfImages objectAtIndex:indexPath.row]]; [cell.contentView addSubview:imageView]; return cell; </code></pre> <p>}</p> <p>Now run it will work ..</p>
 

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