Ios 从目标c中的字符串数组中获取简单值
我的代码就像Ios 从目标c中的字符串数组中获取简单值,ios,objective-c,Ios,Objective C,我的代码就像 NSString *str=[arrInitiatives valueForKey:@"FileName"]; NSLog(@"file name ----> %@",str); NSString *imageUrl = [NSString stringWithFormat:@"%@%@", PUBLIC_UTILITY_FORMS_URL,str]; NSLog(@"----> %@",imageUrl); [_image_imageview setImageW
NSString *str=[arrInitiatives valueForKey:@"FileName"];
NSLog(@"file name ----> %@",str);
NSString *imageUrl = [NSString stringWithFormat:@"%@%@", PUBLIC_UTILITY_FORMS_URL,str];
NSLog(@"----> %@",imageUrl);
[_image_imageview setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:[UIImage imageNamed:@"noimage.png"]];
//http://setupolice.org/brcsetu/UploadFile/Lighthouse4908.jpg
从这个代码中,我将得到这个
file name ----> (
"Lighthouse4908.jpg"
)
----> http://setupolice.org/brcsetu/UploadFile/(
"Lighthouse4908.jpg"
)
I want this
----> http://setupolice.org/brcsetu/UploadFile/Lighthouse4908.jpg
试试这个
NSString *str=[[arrInitiatives valueForKey:@"FileName"] objectAtIndex:0];
问候,
阿米特试试这个
NSString *str=[[arrInitiatives valueForKey:@"FileName"] objectAtIndex:0];
问候,
Amit使用代码创建str变量时
NSString *str=[arrInitiatives valueForKey:@"FileName"];
实际上,它不返回NSString对象,而是返回NSArray对象。这就是为什么文件名位于日志中的括号内:
file name ----> (
"Lighthouse4908.jpg"
)
如果您确定文件名将始终存在于数组中,您可以尝试@Amit Kalghatgi在其答案中建议的方法
问题是,当此数组为空时,您将在执行此代码时收到一个错误。我宁愿这样做:
NSArray *filenames = [arrInitiatives valueForKey:@"FileName"];
NSString *str = nil;
if (filenames.count) {
str =[arrInitiatives valueForKey:@"FileName"];
}
NSLog(@"file name ----> %@",str);
当然,在创建imageUrl之前,您必须检查str是否为nil。当您使用代码创建str变量时
NSString *str=[arrInitiatives valueForKey:@"FileName"];
实际上,它不返回NSString对象,而是返回NSArray对象。这就是为什么文件名位于日志中的括号内:
file name ----> (
"Lighthouse4908.jpg"
)
如果您确定文件名将始终存在于数组中,您可以尝试@Amit Kalghatgi在其答案中建议的方法
问题是,当此数组为空时,您将在执行此代码时收到一个错误。我宁愿这样做:
NSArray *filenames = [arrInitiatives valueForKey:@"FileName"];
NSString *str = nil;
if (filenames.count) {
str =[arrInitiatives valueForKey:@"FileName"];
}
NSLog(@"file name ----> %@",str);
当然,在创建imageUrl之前,您必须检查str是否为nil。检查NSString类文档,他们有方法告诉路径扩展名和文件名等检查NSString类文档,他们有方法告诉路径扩展名和文件名等