Sorry but I cant think of how to word the question. This is what I am trying to do. I have an xml file that contains
<Image1>pic1.jpg</Image1>
<Image2>pic2.jpg</Image2>
<Image3>pic3.jpg</Image3>
<ImageCount>3</ImageCount>
I am creating a url to show the pic. As I click "next" to view the next image I need to create the next url. I know it would be something like this but I cant wrap my head around it this morning.
if (onImageCount <= totalImageCount) {
//here we are on the second image request. we need to create a string to pass the "nextimageurl". this string points to which "Image1,2,3," xml tag to pull up next
nextImageURL = [NSStri开发者_JS百科ng stringWithFormat:@"http://www.pictureshostedhere.com/%@",selectedVehicle.Image[onImageCount]];
imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:nextImageURL]];
carImage = [[UIImageView alloc] initWithFrame:CGRectMake(46,8,228,171)];
carImage.image = [UIImage imageWithData:imageData];
[scrollView addSubview:carImage];
//[self.view sendSubviewToBack:carImage];
[carImage release];
Any help would be great!
Something like this perhaps...
onImageCount++;
if (onImageCount <= totalImageCount) {
nextImageURL = [NSString stringWithFormat:@"http://www.pictureshostedhere.com/%@",[self nextImageFromXML:onImageCount]];
// Other stuff...
}
then, somewhere in your code:
-(NSStrng*)nextImageFromXML:(NSUInteger)count
{
// Somewhere you've already parsed the XML into an Array
return [xmlArray objectAtIndex:count];
}
The shortcut would be just...
nextImageURL = [NSString stringWithFormat:@"http://www.pictureshostedhere.com/%@",[xmlArray objectAtIndex:onImageCount]]; // Where xmlArray returns the appropriate string
精彩评论