我是菜鸟,我无法弄清楚如何将我的应用数据移植到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