0

我是一个菜鸟,我不知道如何将我的应用程序数据移植到 plist,以便我可以将它放在服务器上。

我遵循了一个在线教程,效果很好,但我无法理解该应用程序的实际制作方式,以便我可以远程更新它。

我尝试了很多书籍、在线资源并联系了 lynda.com 的讲师,但在 6 个月内仍然没有弄清楚这一点。

它快把我逼疯了。我认为应用程序的设置方式让我感到困惑。无论如何,在最后的努力中,我正在向大师寻求帮助。

** 第一篇文章,所以我会尽量包含我认为相关的所有内容,但如果需要更多信息,请告诉我**

基本上,使用情节提要,我有一个表格视图,它可以转到另一个视图以根据所选单元格显示图像和更多信息。所以我认为我需要的是一个包含一系列字典的 plist。

这是原始代码,不使用 plist:

//Data.h

#import <Foundation/Foundation.h>

@interface Data : NSObject

@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSString *filename;
@property (nonatomic, strong) NSString *notes;

@end

// Data.m #import "Data.h"

@implementation Data


@synthesize name,filename,notes;

@end


//  TableViewController.h


#import <UIKit/UIKit.h>
#import "Data.h"
#import "DisplayViewController.h"



@interface TableViewController : UITableViewController

@end

/
//  TableViewController.m
//

#import "TableViewController.h"

@interface TableViewController ()

@end

@implementation TableViewController

NSMutableArray *subjects;

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    if ([segue.identifier isEqualToString:@"ShowData"]  ){

        DisplayViewController *dvc = [segue destinationViewController];
        NSIndexPath *path = [self.tableView indexPathForSelectedRow];
        Data *c = [subjects objectAtIndex:path.row];
        [dvc setCurrentData:c];
    }
}


- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    subjects = [[NSMutableArray alloc] init];

    Data *object = [[Data alloc] init];

    [object setName:@"testname1"];
        [object setFilename:@"testname1.png"];
        [object setNotes:@"detail description for test name 1"];
    [subjects addObject:object];

    object = [[Data alloc] init];
    [object setName:@"testname2"];
    [object setFilename:@"testname2.png"];
    [object setNotes:@"detail description for test name 2"];
    [subjects addObject:object];

    object = [[Data alloc] init];
    [object setName:@"testname3"];
    [object setFilename:@"testname3.png.png"];
    [object setNotes:@"detail description for test name 3"];
    [subjects addObject:object];

}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return [subjects count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"DataCell1";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    // Configure the cell...

    Data *current = [subjects objectAtIndex:indexPath.row];
    [cell.textLabel setText:[current name]];


    return cell;
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   }

@end


//  DisplayViewController.h


#import <UIKit/UIKit.h>
#import "Data.h"
#import "InfoViewController.h"

@interface DisplayViewController : UIViewController

@property (strong, nonatomic) Data *currentData;
@property (weak, nonatomic) IBOutlet UIImageView *currentImage;

@end

//  DisplayViewController.m

#import "DisplayViewController.h"

@interface DisplayViewController ()

@end

@implementation DisplayViewController

@synthesize currentData;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIImage *image  = [UIImage imageNamed:[currentData filename]];

    [self.currentImage setImage:image];
    [self setTitle:[currentData name]];
}

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender   {

    InfoViewController *ivc = [segue destinationViewController];
    [ivc setCurrentData:[self currentData]];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
4

0 回答 0