尝试从plist中获取一些数据到MWPhotoBrowser示例应用程序。
任何想法怎么做?
UIViewController *converterController = nil;
NSMutableArray *photos = [[NSMutableArray alloc] init];
converterController = [[MWPhotoBrowser alloc] initWithPhotos:photos];
converterController.hidesBottomBarWhenPushed = YES;
//here individual images can be added. However need to add images from a plist.
[photos addObject:[MWPhoto photoWithFilePath:[[NSBundle mainBundle] pathForResource:@"image1" ofType:@"jpg"]]];
[photos addObject:[MWPhoto photoWithFilePath:[[NSBundle mainBundle] pathForResource:@"image2" ofType:@"jpg"]]];
[photos addObject:[MWPhoto photoWithFilePath:[[NSBundle mainBundle] pathForResource:@"image3" ofType:@"jpg"]]];
[photos addObject:[MWPhoto photoWithFilePath:[[NSBundle mainBundle] pathForResource:@"image4" ofType:@"jpg"]]];
if (converterController) {
[self.navigationController pushViewController:converterController animated:YES];
[converterController release];
}
[photos release];
可以单独添加对象,如上所示,但不能使用plist。
有人可以分享想法吗?
感谢
答案 0 :(得分:0)
瓦特 我得到了这个,但它不起作用。
SString *path = [[NSBundle mainBundle] pathForResource:
@"ImageData" ofType:@"plist"];
// Build the array from the plist
photos = [[NSMutableArray alloc] initWithContentsOfFile:path];
崩溃了应用。 我必须使用MWPhoto属性。
帮助任何人? 也许Michael Waterfall想要研究一下这个?
编辑:
好的,这是工作代码(到目前为止它工作正常)
NSUInteger nimages = 0;
for (; ; nimages++) {
NSString *nameOfImage_ = @"imageSufix";
NSString *imageName = [NSString stringWithFormat:@"%@%d.jpg", nameOfImage_, (nimages + 1)];
//NSLog(@"Name is %@", imageName); log the names
image = [UIImage imageNamed:imageName];
if (image == nil) {
break;
}
[photos addObject:[MWPhoto photoWithImage:image]];