2012-11-25 19 views
0

我試圖製作一個使用相片瀏覽器的應用程序 決定使用MWPhotoBrowser。帶按鈕和錯誤的MWPhotoBrowser handeling

這是代碼,但我似乎無法使其工作:

ViewController.h

#import <UIKit/UIKit.h> 
#import "MWPhotoBrowser.h" 

@interface ViewController : UIViewController<MWPhotoBrowserDelegate> { 
    NSArray *_photos; 
    UISegmentedControl *_segmentedControl; 
} 
@property (nonatomic, retain) NSArray *photos; 
- (IBAction)billede:(id)sender; 

@end 

ViewController.m

#import "ViewController.h" 

@interface ViewController() 

@end 

@implementation ViewController 
@synthesize photos = _photos; 


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     UIBarButtonItem *item = [[[UIBarButtonItem alloc] initWithCustomView:_segmentedControl] autorelease]; 
     self.navigationItem.rightBarButtonItem = item; 
     self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:nil action:nil] autorelease]; 
    } 
    return self; 
} 


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 
- (IBAction)billede:(id)sender { 

    //show your photo whit url 
    NSMutableArray *photos = [[NSMutableArray alloc] init]; 
    MWPhoto *photo; 
    { 
    photo = [MWPhoto photoWithFilePath:[[NSBundle mainBundle] pathForResource:@"photo2l" ofType:@"jpg"]]; 
    photo.caption = @"The London Eye is a giant Ferris wheel situated on the banks of the River Thames, in London, England."; 
    [photos addObject:photo]; 
    } 

    self.photos = photos; 

    // Create browser 
    MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self]; 
    browser.displayActionButton = YES; 

    //browser.wantsFullScreenLayout = NO; 
    //[browser setInitialPageIndex:2]; 

    // Show 
    if (_segmentedControl.selectedSegmentIndex == 0) { 
     // Push 
     [self.navigationController pushViewController:browser animated:YES]; 
    } else { 
     // Modal 
     UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:browser]; 
     nc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; 
     [self presentModalViewController:nc animated:YES]; 
     [nc release]; 
    } 



} 


#pragma mark - MWPhotoBrowserDelegate 

- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser { 

    return _photos.count; 

} 



- (MWPhoto *)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex: (NSUInteger)index { 

    if (index < _photos.count) 

     return [_photos objectAtIndex:index]; 

    return nil; 

} 

@end 

我曾與ARC和嘗試都wooout ARC

沒有ARC我得到3個錯誤:

Undefined symbols for architecture i386: "_OBJC_CLASS_$_MWPhoto", referenced from: objc-class-ref in ViewController.o "_OBJC_CLASS_$_MWPhotoBrowser", referenced from: objc-class-ref in ViewController.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation)

弧我得到2個錯誤

問題1 http://i.imgur.com/pT7qW.png

問題2 http://i.imgur.com/E0X1m.png

我沒有做過在這裏,但我想它全部被包裹在一個按鈕,所以我可以點擊它並在MWPhotoBrowser中顯示圖像

編輯

我已經升級了我的代碼,從我的文件中刪除了ARC,現在我已經設置了目標。 現在可以編譯,但每次我triy點擊按鈕:「billede」我得到:

2012-11-26 23:32:10.955 MWPhotoBrowserTest[10405:c07] -[ViewController galleri:]: unrecognized selector sent to instance 0x947fb20 
2012-11-26 23:32:10.957 MWPhotoBrowserTest[10405:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController galleri:]: unrecognized selector sent to instance 0x947fb20' 
*** First throw call stack: 
(0x1d34012 0x14e9e7e 0x1dbf4bd 0x1d23bbc 0x1d2394e 0x14fd705 0x434920 0x4348b8 0x4f5671 0x4f5bcf 0x4f4d38 0x46433f 0x464552 0x4423aa 0x433cf8 0x1f6ddf9 0x1f6dad0 0x1ca9bf5 0x1ca9962 0x1cdabb6 0x1cd9f44 0x1cd9e1b 0x1f6c7e3 0x1f6c668 0x43165c 0x1e2d 0x1d55) 
libc++abi.dylib: terminate called throwing an exception 
(lldb) 
+1

你將這個庫添加到你的項目中的哪種方式?作爲圖書館還是包括來源? – rmaddy

+0

我包括來源 – 4FunAndProfit

+0

您是否記得添加MWPhoto.m和MWPhotoBrowser.m?兩個文件的目標成員資格是否設置正確? – rmaddy

回答

0

實際上解決了這個問題。 我奮鬥了4天,終於明白了。 我通過https://github.com/mwaterfall/MWPhotoBrowser#method-1-static-library閱讀並瞭解它,終於,但我有用戶標題搜索路徑的問題。 我終於明白了,因爲「../」給我「../ 」導入MWPhotoBrowser文件夾到我的MWPhotoBrowser「項目」文件夾,然後坐在用戶標題搜索路徑「..」而不是「../ 」 ../

希望這可以幫助任何可能與我站在同一問題上的人!

順便說一句,感謝您的幫助傢伙! :-)

+0

您是否將其設置爲遞歸搜索?我發現自己也在爲此苦苦掙扎,但只有當我試圖歸檔我的項目時纔會發生...... –

1

附件1: 不能添加對象的NSArray,使用的NSMutableArray代替。

附件2: UIView沒有方法「reloadData」,但是例如UITableView。

+0

Paul: 1一旦我到達我的電腦,我就會嘗試它! 2.嘗試UITableView時出現錯誤 – 4FunAndProfit