从 IOS 中的 plist 获取字符串值
getting string value from plist in IOS
我一直在研究 iOS.I 中的 plist,已将字体样式 Marker Felt Thin 25.0 保存为 plist 中的字符串。
现在我想检索该字符串并将字体分配给我的表格视图单元格文本。
虽然我正在尝试不影响电池,但为什么会这样...?
NSString *path = [[NSBundle mainBundle] pathForResource:@"myPlist" ofType:@"plist"];
// Load the file content and read the data into arrays
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
cell.textLabel.font=[UIFont fontWithName:[[dict objectForKey:@"Font"]size:15]];
我该怎么做...?
这里是 plist 截图
PList[2423:126298]{
名称 = (
阿吉特,
布万,
嘉莉,
大卫,
埃泽尔,
法罗克,
库雷塞马
象头神,
哈里斯,
我是男人,
贾加迪什,
凯文,
露西,
马诺杰,
内森,
奥兰,
帕万,
雷米,
桑,
塔努,
乌尔米拉
维迪亚,
沃森,
夏比,
亚米尼,
扎希尔
);
字体 = "Marker Felt Thin ";
} 字典值
我认为你的问题出在行
cell.textLabel.font=[UIFont fontWithName:[[dict objectForKey:@"Font"]size:15]];
可能是这样的:
cell.textLabel.font = [UIFont fontWithName:[dict objectForKey:@"Font"] size:15]];
字典键是 font
而不是 Font
。按键区分大小写。
使用:
cell.textLabel.font = [UIFont fontWithName:dict[@"font"] size:15];
我一直在研究 iOS.I 中的 plist,已将字体样式 Marker Felt Thin 25.0 保存为 plist 中的字符串。
现在我想检索该字符串并将字体分配给我的表格视图单元格文本。
虽然我正在尝试不影响电池,但为什么会这样...?
NSString *path = [[NSBundle mainBundle] pathForResource:@"myPlist" ofType:@"plist"];
// Load the file content and read the data into arrays
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
cell.textLabel.font=[UIFont fontWithName:[[dict objectForKey:@"Font"]size:15]];
我该怎么做...?
这里是 plist 截图
PList[2423:126298]{ 名称 = ( 阿吉特, 布万, 嘉莉, 大卫, 埃泽尔, 法罗克, 库雷塞马 象头神, 哈里斯, 我是男人, 贾加迪什, 凯文, 露西, 马诺杰, 内森, 奥兰, 帕万, 雷米, 桑, 塔努, 乌尔米拉 维迪亚, 沃森, 夏比, 亚米尼, 扎希尔 ); 字体 = "Marker Felt Thin "; } 字典值
我认为你的问题出在行
cell.textLabel.font=[UIFont fontWithName:[[dict objectForKey:@"Font"]size:15]];
可能是这样的:
cell.textLabel.font = [UIFont fontWithName:[dict objectForKey:@"Font"] size:15]];
字典键是 font
而不是 Font
。按键区分大小写。
使用:
cell.textLabel.font = [UIFont fontWithName:dict[@"font"] size:15];