gpt4 book ai didi

iphone - 带按钮和错误处理的照片浏览器

转载 作者:行者123 更新时间:2023-11-29 04:17:01 26 4
gpt4 key购买 nike

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

这是代码,但我似乎无法使其工作:

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 和不使用 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)

使用 ARC 我遇到 2 个错误

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

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

我没有在这里完成它,但我希望将其全部包含在一个按钮中,以便我可以单击该按钮并在 MWPhotoBrowser 中显示图像

编辑

我已经升级了我的代码,从我的文件中删除了 ARC,现在我已经设置了正确的目标。它现在将编译,但每次我尝试单击按钮:“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:您无法将对象添加到 NSArray,请改用 NSMutableArray。

附件2:UIView 没有方法“reloadData”,但例如 UITableView 有。

关于iphone - 带按钮和错误处理的照片浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13556787/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com