首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带按钮和错误处理的MWPhotoBrowser

带按钮和错误处理的MWPhotoBrowser
EN

Stack Overflow用户
提问于 2012-11-25 23:39:20
回答 2查看 1.5K关注 0票数 0

我正在尝试制作一个应用程序,它使用的是一个决定与MWPhotoBrowser一起使用的照片浏览器。

这是代码,但我似乎无法让它工作:

ViewController.h

代码语言:javascript
复制
#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

代码语言:javascript
复制
#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和wothout ARC

如果没有ARC,我会得到3个错误:

未定义的体系结构符号:"_OBJC_CLASS_$_MWPhoto",引用自: objc-class-ref in ViewController.o "_OBJC_CLASS_$_MWPhotoBrowser",引用: objc-class-ref in ViewController.ld:符号(S)未找到用于体系结构的i386 clang: i386:链接器命令失败,退出代码1(使用-v查看调用)

有了ARC,我得到了两个错误

问题1 http://i.imgur.com/pT7qW.png

问题2 http://i.imgur.com/E0X1m.png

我没有在这里做过,但是我希望它能被一个按钮包裹起来,这样我就可以点击它,在MWPhotoBrowser中显示一个图像。

编辑

我已经升级了我的代码,从我的文件中删除ARC,现在我已经设置了目标正确。它现在将编译,但是每次我试着点击按钮:"billede“,我得到:

代码语言:javascript
复制
    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) 
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-11-29 21:46:32

实际上解决了这个问题。我挣扎了4天终于拿到了。我阅读了https://github.com/mwaterfall/MWPhotoBrowser#method-1-static-library并理解了它,但我在用户头搜索路径上遇到了问题。我终于得到了它,将MWPhotoBrowser文件夹输入到我的MWPhotoBrowser“项目”文件夹中,然后坐在用户头上搜索路径到“.”而不是“./”,因为“./”给了我“././

希望这能帮助那些可能和我站在同一个问题上的人!

顺便说一句,谢谢你们的帮助!

票数 0
EN

Stack Overflow用户

发布于 2012-11-25 23:51:52

附件1:不能将对象添加到NSArray,而是使用NSMutableArray。

附件2: UIView没有"reloadData“方法,但是UITableView有。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13556787

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档