我对应用程序开发场景非常陌生,并尝试使用互联网上的信息以及几周前我做过的“短期课程”。
我正试图将信息从我的视图控制器转移到辅助控制器。在第一个视图控制器中,用户输入一个代码,它会查找plist并显示3个代码。
我将提供我的代码,非常感谢任何帮助:
我有3个控制器。
导航控制器
查看Controller.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (strong, nonatomic) IBOutlet UITextField *codeTextField;
@end
查看Controller.m
#import "ViewController.h"
#import "ViewController.h"
#import "DetailViewController.h"
@interface ViewController ()
@property (strong, nonatomic) NSArray *ID;
@end
@implementation GBRFViewController
#pragma mark View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Automatically present the keyboard when this screen is first displayed
[self.headcodeTextField becomeFirstResponder];
NSString *dataFilePath = [[NSBundle mainBundle] pathForResource:@"ID" ofType:@"plist"];
self.ID = [NSArray arrayWithContentsOfFile:dataFilePath];
}
#pragma mark Scene management
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Move the search term across into the results view controller as it is presented
GBRFDetailViewController *controller = segue.destinationViewController;
controller.searchTerm = self.headcodeTextField.text;
}
#pragma mark Text field delegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
// Kick off the segue manually when the return key is tapped
[self performSegueWithIdentifier:@"searchSegue" sender:self];
return YES;
}
@end
DetailViewController.h
#import <UIKit/UIKit.h>
@interface GBRFDetailViewController : UIViewController
@property (strong, nonatomic) NSDictionary *IDDetail;
@property (strong, nonatomic) NSString *searchTerm;
@end
DetailViewController.m
#import "DetailViewController.h"
@interface DetailViewController ()
@property (strong, nonatomic) UIPopoverController *masterPopoverController;
@property (strong, nonatomic) IBOutlet UILabel *titleLabel;
@property (strong, nonatomic) IBOutlet UILabel *code1Label;
@property (strong, nonatomic) IBOutlet UILabel *code2Label;
@property (strong, nonatomic) IBOutlet UILabel *code3Label;
@end
@implementation DetailViewController
#pragma mark View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Setting the title on the view controller will automatically update the navigation bar title
self.title = self.searchTerm;
// Only set the outlets up if the book detail is set
if (self.IDDetail)
[self configureView];
}
- (void)configureView
{
// The title of the view controller is displayed in the navigation bar
self.title = self.IDDetail[@"Title"];
// Take the data out of the dictionary and populate the outlets
self.titleLabel.text = self.IDDetail[@"ID"];
self.code1Label.text = self.IDDetail[@"Code1"];
self.code2Label.text = self.IDDetail[@"Code2"];
self.code3Label.text = self.IDDetail[@"Code3"];
}
#pragma mark Property overrides
- (void)setIDDetail:(NSDictionary *)IDDetail
{
if (_IDDetail != IDDetail) {
_IDDetail = IDDetail;
[self configureView];
}
}
#pragma mark Split view controller
- (void)splitViewController:(UISplitViewController *)splitViewController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController
{
[self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];
self.masterPopoverController = popoverController;
barButtonItem.title = @"IDs";
}
- (void)splitViewController:(UISplitViewController *)splitViewController willShowViewController:(UIViewController *)viewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
[self.navigationItem setLeftBarButtonItem:nil animated:YES];
self.masterPopoverController = nil;
}
@end
我的Plist采用以下格式(虽然有超过25000行)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ID</key>
<string>0A00</string>
<key>M=0</key>
<string>0</string>
<key>M=1</key>
<string>1533</string>
<key>M=2</key>
<string>3066</string>
</dict>
</plist>