你好,我有一個問題,這個Objective-C的字符串問題
for (NSString* fileName in fileList){
if ([fileName rangeOfString:@".png"].location != NSNotFound ) {
int x= col*130;
NSLog(@"add %@", fileName);
//create dynamically a nice thumbnail
UIImage* img = [UIImage imageWithContentsOfFile:
[self.documentsDir stringByAppendingPathComponent:fileName]
];
UIImageView* imgView = [[UIImageView alloc] initWithImage:img];
imgView.frame = CGRectMake(0, 0, 110, 110);
imgView.contentMode = UIViewContentModeScaleAspectFill;
imgView.clipsToBounds = YES;
UIButton* imgBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[imgBtn addTarget:self action:@selector(imgPressed:) forControlEvents:UIControlEventTouchUpInside];
imgBtn.frame = CGRectMake(x, row*130, 120, 120);
//imgBtn.backgroundColor = [UIColor lightGrayColor];
[imgBtn addSubview:imgView];
[self.canvas addSubview:imgBtn];
[imgView release];
col++;
if (x > 760) {
row++;
col = 0;
}
}
這使得非常好的縮略圖,但我想只有特定名稱的文件,使之,所以我有問題如何只加載特定的名稱類型。像例如我有名爲... city1,city2,city3的圖像,都是png類型,我也有car1,car2 ....也是png。但是,一旦我想要只載入城市和唯一的一次汽車....
是否有可能只加載城市或僅汽車????
感謝所有。 我不知道如何對字符串進行精確比較。
我會用這樣的 如果(文件名isequaltoString:@ 「汽車%」)
,但它不工作.. =(
這不是一個Xcode的問題,這是一個objec t-c問題。 – rooftop 2012-03-01 19:17:48
真:)你不知道如何得到這個工作?:( – 2012-03-01 19:20:04
看一看NSString的編程指南:https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/字符串/用品/ SearchingStrings.html#// apple_ref/DOC/UID/20000149-CJBBGBAI – gregheo 2012-03-01 19:21:36