Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何实现在plist中搜索字符串?_Ios_Objective C_Search_Plist_Uisearchcontroller - Fatal编程技术网

Ios 如何实现在plist中搜索字符串?

Ios 如何实现在plist中搜索字符串?,ios,objective-c,search,plist,uisearchcontroller,Ios,Objective C,Search,Plist,Uisearchcontroller,我试了所有的方法,但都不起作用。我有一个加载plist的tableview。我正在尝试实现搜索功能 这是我的密码 #import <UIKit/UIKit.h> @interface TableViewController : UITableViewController <UISearchDisplayDelegate, UISearchBarDelegate> @property (strong, nonatomic) IBOutlet UITableView *tab

我试了所有的方法,但都不起作用。我有一个加载plist的tableview。我正在尝试实现搜索功能

这是我的密码

#import <UIKit/UIKit.h>
@interface TableViewController : UITableViewController <UISearchDisplayDelegate, UISearchBarDelegate>
@property (strong, nonatomic) IBOutlet UITableView *tableView;
@property(nonatomic)NSMutableArray *itemList;
@property (nonatomic)NSMutableArray *filteredNames;
@property (weak, nonatomic) IBOutlet UISearchBar *searchBar;
@property (nonatomic, strong) UISearchController *searchController;
这是我的.m文件

- (void)viewDidLoad {
    [super viewDidLoad];

    _searchController = [[UISearchController alloc]init];

    self.filteredNames = [[NSMutableArray alloc]init];


    [self.tableView  dataSource];
    [self.tableView delegate];
    [self.tableView reloadData];
}
这就是我的plist

<?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>FilmsPlaying</key>
    <array>
        <dict>
            <key>ZFILMTIME</key>
            <integer>90</integer>
            <key>ZFILMDATESTART</key>
            <date>2015-04-01T09:15:42Z</date>
            <key>ZFILMCONTENT</key>
            <string>bla bla bla </string>
            <key>ZFILMDIRECTOR</key>
            <string>Don Hall,Chris Williams</string>
            <key>ZFILMID</key>
            <string></string>
            <key>ZFILMIMAGE</key>
            <string>bla.jpg</string>
            <key>ZFILMNAME</key>
            <string> Big Hero 6</string>
            <key>ZFILMTYPE</key>
            <string>bla bla bla </string>
            <key>ZFILMVOTE</key>
            <integer>10</integer>
        </dict>
        <dict>
            <key>ZFILMTIME</key>
            <integer>90</integer>
            <key>ZFILMDATESTART</key>
            <date>2015-04-01T09:15:42Z</date>
            <key>ZFILMCONTENT</key>
            <string>bla bla bla .</string>
            <key>ZFILMDIRECTOR</key>
            <string>Frankie Chung</string>
            <key>ZFILMID</key>
            <string></string>
            <key>ZFILMIMAGE</key>
            <string>bla.jpg</string>
            <key>ZFILMNAME</key>
            <string>bla bla bla </string>
            <key>ZFILMTYPE</key>
            <string>bla bla bla </string>
            <key>ZFILMVOTE</key>
            <real>9.5</real>
        </dict>
</array>
</dict>

电影放映
ZFILMTIME
90
ZFILMDATESTART
2015-04-01T09:15:42Z
ZFILMCONTENT
呜呜呜呜
ZFILMDIRECTOR
唐·霍尔,克里斯·威廉姆斯
ZFILMID
ZFILMIMAGE
bla.jpg
ZFILMNAME
大英雄6
ZFILMTYPE
呜呜呜呜
ZFILMVOTE
10
ZFILMTIME
90
ZFILMDATESTART
2015-04-01T09:15:42Z
ZFILMCONTENT
呜呜呜呜。
ZFILMDIRECTOR
钟智行
ZFILMID
ZFILMIMAGE
bla.jpg
ZFILMNAME
呜呜呜呜
ZFILMTYPE
呜呜呜呜
ZFILMVOTE
9.5
我在等待您的建议,谢谢您搜索NSDictionary的数组(电影) 因此,在谓词中使用NSDionary中的SELF.keyname

NSString *filePathBundle = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"];
NSDictionary *root = [NSDictionary dictionaryWithContentsOfFile:filePathBundle];
NSArray *films = [root objectForKey:@"FilmsPlaying"];

NSLog(@"%@",films);

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.ZFILMNAME CONTAINS[cd] %@", self.searchBar.tex];

NSArray *searchResult = [films filteredArrayUsingPredicate:predicate];
   NSLog(@"%@",searchResult);
您可以搜索NSDictionary的数组(电影) 因此,在谓词中使用NSDionary中的SELF.keyname

NSString *filePathBundle = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"];
NSDictionary *root = [NSDictionary dictionaryWithContentsOfFile:filePathBundle];
NSArray *films = [root objectForKey:@"FilmsPlaying"];

NSLog(@"%@",films);

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.ZFILMNAME CONTAINS[cd] %@", self.searchBar.tex];

NSArray *searchResult = [films filteredArrayUsingPredicate:predicate];
   NSLog(@"%@",searchResult);

添加此代码并选中:NSPredicate*谓词=[NSPredicate predicateWithFormat:@“SELF CONTAINS[cd]@”,SELF.searchBar.text];不,它不起作用。应用程序刚刚崩溃添加此代码并检查:NSPredicate*谓词=[NSPredicate predicateWithFormat:@“SELF CONTAINS[cd]@”,SELF.searchBar.text];不,它不起作用。应用程序刚刚崩溃。它仍然不工作,并且出现错误。有什么想法吗?@ahmetberkaycalisti检查更新的代码的工作情况并获取结果,您可能在显示结果数据时出错。它仍然不工作,并获取错误。有什么想法吗?@ahmetberkaycalisti检查更新的代码及其工作并获得结果,您可能在显示结果数据时出错