Question

I'm using a plist for the data in an app but I won't want the data to be stored locally(a lot of images), I want the images to be uploaded on a server and to be able to read them from there. Is it possible using plist?

here's the plist structure for an item:

<key></key>
        <string> Servings: 4
Preheat oven to 350˚F. Grease a 1 to 2-quart baking dish.
In a medium bowl, toss together the bread cubes and butter.
In a large bowl, toss together the apples, agave syrup, lemon juice, cinnamon, allspice, and salt.
Cover and bake 30 minutes. Uncover and bake 20 to 30 minutes longer or until bread cubes are browned.
</string>
        <key>smallImage</key>
        <string>s130.png</string>
        <key>ingredients</key>
        <string>2 cups cubed sourdough bread (½-inch cubes) 
        1 tablespoon melted butter 
        3 cups thinly sliced, peeled apples 
        ¼ cup agave syrup 
        2 teaspoons fresh lemon juice 
        ½ teaspoon ground cinnamon 
        ¼ teaspoon ground allspice 
        Salt to taste
</string>
        <key>title</key>
        <string>Apple Brown Betty
</string>
        <key>coverImage</key>
        <string>130.png</string>
    </dict>

and the way I load the data right now from plist:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    recipes = [[BooksLibraryDao alloc] initWithLibraryName:@"TestData"];

    [self.tableView reloadData];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [recipes libraryCount];
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *cellIdentifier = @"Game Cell Identifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
    }

    cell.textLabel.text = [[recipes libraryItemAtIndex:indexPath.row] valueForKey:@"title"];
    UIFont *myFont = [ UIFont fontWithName: @"Arial" size: 14.0 ];
    cell.textLabel.font  = myFont;
    cell.imageView.image = [UIImage
                            imageNamed:[[recipes libraryItemAtIndex:indexPath.row] valueForKey:@"smallImage"]];
    cell.accessoryView = nil;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    return cell;

}
Was it helpful?

Solution

For load images from server you can use SDWEBIMAGE . Download this github link and Copy this into your project. Now You need to,

#import <SDWebImage/UIImageView+WebCache.h>

Then you can Do this,

[YourImageView setImageWithURL:[NSURL URLWithString:@"Your URL link"]
                   placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

Where Placeholderimage is default image when image is not available on server. Hope this help you!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top