現在、私はPhotoGalleryControllerを作成し、MWPhotoBrowser以来MWPhotoBrowserのコンテナとしてのUIViewControllerのサブクラスであることを使用しています。私はシミュレータでアプリケーションを起動するとき
はしかし、私はPhotoBrowserがロードされたことを示唆し、中央に円形で、空白の画面を取得しますが、返される写真はありません。
私は先に行って、すべての私のデリゲートメソッドをログに記録し、numberOfPhotosが呼び出されていたことがわかったが、MWPhotoオブジェクトを返すことになっていた実際の機能であっても呼び出されることはありませんでした!写真のオブジェクトの実際の負荷が私はコンテナのViewController内のすべての適切なデリゲートメソッドを実装しているにもかかわらず、完成されることはありません、なぜ
は、私はかなりよく分かりません。
私は応答API呼び出しによって与えられ、同様self.photoListをプリントアウトの出力を確認しました。それらは正常であるように思われるので、私はなぜそれがどんな写真も返さないと確信していません。
PhotoGalleryController.m
#import "PhotoGalleryController.h"
#import "MZApi.h"
#import "MZUser.h"
@implementation PhotoGalleryController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
//Make the HTTP request and setup the photo array in MZUser. Change from "usertext" later.
[MZApi loadOwnPhotoWithUserID:@"usertext" andCompletionHandler:^(NSMutableArray *photos, NSError *error) {
if(photos!=nil){
self.userPhotoList = photos;
[[MZUser getCurrentUser]setPhotoList:self.userPhotoList];
//NSLog(@" %@", self.userPhotoList);
//Should currently be null because CurrentUser is not created yet.
}
else{
NSLog(@"Failed to allocate photos!");
}
}];
MWPhotoBrowser *browser = [[MWPhotoBrowser alloc]initWithDelegate:self];
browser.displayActionButton = YES; // Show action button to allow sharing, copying, etc (defaults to YES)
browser.displayNavArrows = NO; // Whether to display left and right nav arrows on toolbar (defaults to NO)
browser.displaySelectionButtons = NO; // Whether selection buttons are shown on each image (defaults to NO)
browser.enableGrid = YES; // Whether to allow the viewing of all the photo thumbnails on a grid (defaults to YES)
browser.startOnGrid = YES; // Whether to start on the grid of thumbnails instead of the first photo (defaults to NO)
[self.view addSubview:browser.view];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(NSUInteger) numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser{
return [self.userPhotoList count];
}
- (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index{
if(index<self.userPhotoList.count){
NSString *temp = [[self.userPhotoList objectAtIndex:index]file_url];
MWPhoto *photo = [MWPhoto photoWithURL:[NSURL URLWithString:temp]];
return photo;
}
return nil;
}
-(id <MWPhoto>) photoBrowser:(MWPhotoBrowser *)photoBrowser thumbPhotoAtIndex:(NSUInteger)index{
NSLog(@"Thumb Delegate Called!");
if(index<self.userPhotoList.count){
NSString *temp = [[self.userPhotoList objectAtIndex:index]file_url];
MWPhoto *photo = [MWPhoto photoWithURL:[NSURL URLWithString:temp]];
return photo;
}
return nil;
}
@end
PhotoGalleryController.h
#import <UIKit/UIKit.h>
#import "MWPhotoBrowser.h"
@interface PhotoGalleryController : UIViewController <MWPhotoBrowserDelegate>
@property(strong, nonatomic) NSMutableArray * userPhotoList;
- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser;
- (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index;
- (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser thumbPhotoAtIndex:(NSUInteger)index;
@end
サーバーの応答サンプル:あなたがしているときは、表示するブラウザを追加している
(
{
dislikes = 0;
"file_url" = "http://localhost:3000/static/photos/2.jpg";
likes = 0;
"photo_id" = 2;
"user_id" = kai1234;
},
{
dislikes = 4;
"file_url" = "http://localhost:3000/static/photos/1.jpg";
likes = 5;
"photo_id" = 1;
"user_id" = kai1234;
}
)
のようになります。 self.userPhotoList = photosのコメントアウトとは別に、私は無効なコンテキストを取得します。これは、ブロック内からself.viewを呼び出すと、ViewControllerではなくMZApiが呼び出されるからです。 –
ブロック内でself.viewを呼び出すと、viewcontrollerのビューが参照されます。このコードは、応答が受信された後に呼び出されています。 file_urlが何を参照していないのですか? – Mortgy
file_urlは、静的ファイルシステム上で提供される画像を指すリンクに行きます。 –