我有一个名为aux的字符串,它包含六个url图像,我想分割这些图像并在UIImage视图中显示图像就像
http://nssdc.gsfc.nasa.gov/planetary/image/cassini_titan_15.jpg
http://nssdc.gsfc.nasa.gov/planetary/image/cassini_titan_15.jpg
http://nssdc.gsfc.nasa.gov/planetary/image/cassini_titan_15.jpg
http://nssdc.gsfc.nasa.gov/planetary/image/cassini_titan_15.jpg
http://nssdc.gsfc.nasa.gov/planetary/image/cassini_titan_15.jpg
http://nssdc.gsfc.nasa.gov/planetary/image/cassini_titan_15.jpg
我想使用if条件分割这些图像并将其显示在图像视图中。
答案 0 :(得分:1)
您只需要确定将它们分隔的字符串。如果你有,你可以使用-[NSString componentsSeparatedByString:]
方法。例如:
//This assumes they are separated with a comma
NSString *imageString = @"http://nssdc.gsfc.nasa.gov/planetary/image/cassini_titan_15.jpg,http://nssdc.gsfc.nasa.gov/planetary/image/cassini_titan_16.jpg";
NSArray *images = [imageString componentsSeparatedByString:@","];
// Now you have each image as an element on the images array
答案 1 :(得分:1)
如果您从文件中逐行读取这些行,那么您可以尝试这样做:
NSString *urlsList = ... // your list in first post each url on it's line
NSArray *imagesURL = [urlsList componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];