Objective-c:没有在NSArray上获得正确的文本

时间:2017-08-19 17:37:00

标签: ios objective-c uilabel

我想抓住我的plist上的一些数据,它有很多记录

对于那种情况我使用了这段代码

NSString *path = [[NSBundle mainBundle] pathForResource:@"kurdiebg" ofType:@"plist"];
NSArray *plistData = [NSArray arrayWithContentsOfFile:path];
NSPredicate *filter = [NSPredicate predicateWithFormat:@"english = %@", self.searchQwery.text];
NSArray *filtered = [plistData filteredArrayUsingPredicate:filter];
NSLog(@"found matches: %@ : %@", filtered,[filtered valueForKey:@"kurdi"]);

NSString*nss = [NSString stringWithFormat:@"%@",[filtered valueForKey:@"english"]];
self.lblWord.text = nss;

它在日志上很好,但是在uilabel上它会返回 simulator

NSLog上的

enter image description here

由于

1 个答案:

答案 0 :(得分:1)

你的过滤器是数组od NSdictionary

NSString *path = [[NSBundle mainBundle] pathForResource:@"kurdiebg" ofType:@"plist"];
    NSArray *plistData = [NSArray arrayWithContentsOfFile:path];
    NSPredicate *filter = [NSPredicate predicateWithFormat:@"english = %@", self.searchQwery.text];
    NSArray *filtered = [plistData filteredArrayUsingPredicate:filter];
    NSLog(@"found matches: %@ : %@", filtered,[filtered valueForKey:@"kurdi"]);
    NSString*nss = [NSString stringWithFormat:@"%@",[filtered valueForKey:@"english"]];

    if (filtered.count>0) {
        NSDictionary *dic  = filtered[0];
        self.lblWord.text = dic[@"english"];
    }