Ok, I really tried looking for an example or tutorial in how to achieve what I'm looking for, but haven't had any luck.
I have a PFQueryTableView that passes data to a DetailView (all good there).
My DetailView is a Horizontal ScrollView that gets images from the cell clicked. And here comes my problem: I manage to get the data to pass to the DetailView but I don't know how to set up the images in the ScrollView. Can anyone please send me on the direction of a tutorial or could help me via this question?
Here is my code: (Obviously I'm missing the section where you set up the images to be viewed in the ScrollView.)
BellezaTableViewController.m
#import "BellezaTableViewController.h"
#import "BellezaDetailViewController.h"
#import "BellezaView.h"
@interface BellezaTableViewController ()
@end
@implementation BellezaTableViewController {
}
- (id)initWithCoder:(NSCoder *)aCoder
{
self = [super initWithCoder:aCoder];
if (self) {
self.parseClassName = @"BellezaView";
self.textKey = @"cellTitle";
self.textKey = @"descriptionTitle";
self.pullToRefreshEnabled = YES;
self.paginationEnabled = NO;
self.loadingViewEnabled = YES;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (PFQuery *)queryForTable{
PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
query.cachePolicy = kPFCachePolicyCacheThenNetwork;
return query;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {
static NSString *simpleTableIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
UILabel *cellTitle = (UILabel*) [cell viewWithTag:101];
cellTitle.text = [object objectForKey:@"cellTitle"];
UILabel *descriptionTitle = (UILabel*) [cell viewWithTag:102];
descriptionTitle.text = [object objectForKey:@"descriptionTitle"];
return cell;
}
- (void) objectsDidLoad:(NSError *)error
{
[super objectsDidLoad:error];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showBellezaDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
BellezaDetailViewController *destViewController = segue.destinationViewController;
PFObject *object = [self.objects objectAtIndex:indexPath.row];
BellezaView *bellezaView = [[BellezaView alloc] init];
bellezaView.cellTitle = [object objectForKey:@"cellTitle"];
bellezaView.descriptionTitle = [object objectForKey:@"descriptionTitle"];
bellezaView.image_1 = [object objectForKey:@"image_1"];
destViewController.bellezaView = bellezaView;
}
}
@end
BellezaTableViewController.h
#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
@interface BellezaTableViewController : PFQueryTableViewController
@end
DetailViewController.m
#import "BellezaDetailViewController.h"
#import "BellezaView.h"
@interface BellezaDetailViewController ()
@end
@implementation BellezaDetailViewController
@synthesize lookPhoto, bellezaView, activityIndicator, scrollView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];{
[activityIndicator startAnimating];
[activityIndicator performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:60];
[scrollView setAlwaysBounceHorizontal:YES];
[scrollView setAlwaysBounceVertical:NO];
[scrollView setPagingEnabled:YES];
NSInteger numberOfViews = 3;
for (int i = 0; i < numberOfViews; i++){
This would be the section I do not know how to handle, and can't find any examples to follow through. Should I use an array? If so, how do I retrieve the data if I should have passed it from the PFQueryTable? I found some examples that get images like this code:
image.image = [UIImage imageNamed: [NSString stringWithFormat:@"image_%d", i+1]];
but my problem is that my images have to be fetched by parse. So how do I do that? Please help!
lookPhoto.file = bellezaView.image_1;
[lookPhoto loadInBackground];
[scrollView addSubview:lookPhoto];
}
scrollView.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height);
}
}
- (void)viewDidUnload {
[self setLookPhoto:nil];
[super viewDidUnload];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
DetailViewController.h
#import <UIKit/UIKit.h>
#import "BellezaView.h"
#import <Parse/Parse.h>
@interface BellezaDetailViewController : UIViewController
@property (weak, nonatomic) IBOutlet PFImageView *lookPhoto;
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicator;
@property (nonatomic, strong) BellezaView *bellezaView;
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@end
BellezaView.m
#import "BellezaView.h"
@implementation BellezaView
@synthesize cellTitle, descriptionTitle, image_1;
@end
BellezaView.h
#import <Foundation/Foundation.h>
#import <Parse/Parse.h>
@interface BellezaView : NSObject
@property (nonatomic, strong) NSString *cellTitle;
@property (nonatomic, strong) NSString *descriptionTitle;
@property (nonatomic, strong) PFFile *image_1;
@end
Thanks in advance!
Found a way, Here is my code for the DetailViewController.m file: Hope it helps anyone in need! :)
- (void)viewDidLoad {
[super viewDidLoad];
//Do any additional setup after loading the view.
[activityIndicator startAnimating];
[activityIndicator performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:60];
scrollView.pagingEnabled = YES;
[UIView animateWithDuration:20 animations:^{ScrollNext.alpha = 0.0;}];
NSInteger numberOfViews = 10;
for (int i = 0; i < numberOfViews; i++) {
PFImageView *lookView1 = [[PFImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
lookView1.image = [UIImage imageNamed:@"Lading.jpg"];
lookView1.file = bellezaView.image_1;
[scrollView addSubview:lookView1];
[lookView1 loadInBackground:^(UIImage *image, NSError *error) {
if (!error) {
lookView1.frame = CGRectMake(0,0,self.view.frame.size.width, self.view.frame.size.height);
lookView1.contentMode = UIViewContentModeScaleAspectFit;
scrollView.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height);
}
}];
PFImageView *lookView2 = [[PFImageView alloc] init];
lookView2.frame = CGRectMake(lookView1.frame.size.width*1, 0, 320, 500);
lookView2.file = bellezaView.image_2;
[scrollView addSubview:lookView2];
[lookView2 loadInBackground:^(UIImage *image, NSError *error) {
if (!error) {
lookView2.contentMode = UIViewContentModeScaleAspectFit;
lookView2.frame = CGRectMake(lookView1.frame.size.width*1, 0, self.view.frame.size.width, self.view.frame.size.height);
}
}];
PFImageView *lookView3 = [[PFImageView alloc] init];
lookView3.frame = CGRectMake(lookView1.frame.size.width*2, 0, 320, 500);
lookView3.file = bellezaView.image_3;
[scrollView addSubview:lookView3];
[lookView3 loadInBackground:^(UIImage *image, NSError *error) {
if (!error) {
lookView3.contentMode = UIViewContentModeScaleAspectFit;
lookView3.frame = CGRectMake(lookView1.frame.size.width*2, 0, self.view.frame.size.width, self.view.frame.size.height);
}
}];
//Insert Another View
}
}