好吧,我真的試過尋找一個示例或教程來了解如何實現我正在尋找的內容,但沒有任何運氣。從詳細信息中獲取圖像解析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
在此先感謝!
我是否應該改變頁面視圖? – adriennemhenry