【问题标题】:MWPhotoBrowser add data from plist?MWPhotoBrowser 从 plist 添加数据?
【发布时间】:2012-04-30 11:19:48
【问题描述】:

试图从 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 来完成。

谁能分享一个想法?

谢谢

【问题讨论】:

    标签: iphone sdk nsarray plist


    【解决方案1】:

    w 嗯,我得到了这个,但它不起作用。

    SString *path = [[NSBundle mainBundle] pathForResource:
            @"ImageData" ofType:@"plist"];
    
        // Build the array from the plist  
      photos = [[NSMutableArray alloc] initWithContentsOfFile:path];
    

    使应用程序崩溃。 我必须使用 MWPhoto 属性。

    帮助任何人? 也许迈克尔瀑布想调查一下?

    编辑:

    好的,这是工作代码(到目前为止它工作正常)

     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]];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-29
      • 2011-12-22
      • 2011-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多