2014-03-04 381 views
0

好吧,我真的試過尋找一個示例或教程來了解如何實現我正在尋找的內容,但沒有任何運氣。從詳細信息中獲取圖像解析ScrollView

我有一個PFQueryTableView將數據傳遞給DetailView(這裏都很好)。

我的DetailView是一個水平滾動視圖,從單元格中獲取圖像。我的問題出現了:我設法讓數據傳遞給DetailView,但我不知道如何在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 

Detai lViewController.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++){ 

這將是我不知道如何處理的部分,並不能找到任何例子來跟進。我應該使用數組嗎?如果是這樣,我應該如何檢索數據,如果我應該從PFQueryTable中傳遞它?我發現了一些例子,像這樣的代碼得到的圖像:

image.image = [UIImage imageNamed:[NSString stringWithFormat:@「image_%d」,i + 1]];

但我的問題是,我的圖像必須通過解析獲取。那我該怎麼做?請幫忙!

 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 

在此先感謝!

+0

我是否應該改變頁面視圖? – adriennemhenry

回答

0

找到了一種方法,這裏是我的代碼爲DetailViewController.m文件: 希望它可以幫助任何需要的人!:)

- (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 

    } 
} 
0

如果你有在你PFObject一個屬性,你可以這樣做

PFFile* imageFile = [object objectForKey:@"imageFile"]; 
UIImage* img = nil; 
if (startImage != nil) 
{ 
    img = [[UIImage alloc] initWithData:[imgFile getData]]; 
} 

屬性「鏡像文件」的鏈接,圖像鏈接到圖像解析

請記住,這使得網絡電話,所以你不應該這樣做的主線程

+0

謝謝!但我不認爲它有幫助:( 請參閱,原因是因爲我已經通過點擊單元格的數據並且信息已經設置。每行有5列圖像(在Parse.com中設置)。當你點擊一個單元格時,它會帶你進入一個帶有5個圖像(它自己的類)的滾動視圖。我設法用這個代碼調用1個圖像(因爲我正在查看一個PFImageView) PFImageView.file =(ClassName)。( FileName); 所以在我的情況下,它會是... lookPhoto.file = bellezaView.image_1; 我不知道接下來要做的是將scrollview中的下一個PFImageView設置爲「image_2」 – adriennemhenry