Когда я двигаюсь через объект, мне нужно увеличить 1 цифру, когда я создаю URL - PullRequest
0 голосов
/ 09 апреля 2011

Извините, но я не могу придумать, как сформулировать вопрос. Это то, что я пытаюсь сделать. У меня есть XML-файл, который содержит

<Image1>pic1.jpg</Image1>
<Image2>pic2.jpg</Image2>
<Image3>pic3.jpg</Image3>
<ImageCount>3</ImageCount>

Я создаю URL для показа картинки. Когда я нажимаю «Далее» для просмотра следующего изображения, мне нужно создать следующий URL. Я знаю, что это будет примерно так, но сегодня утром я не могу обернуть голову вокруг него.

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 = [NSString 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];

Любая помощь будет отличной!

1 Ответ

1 голос
/ 09 апреля 2011

Что-то вроде этого возможно ...

onImageCount++;
if (onImageCount <= totalImageCount) {
        nextImageURL = [NSString stringWithFormat:@"http://www.pictureshostedhere.com/%@",[self nextImageFromXML:onImageCount]];
       // Other stuff...
}

тогда, где-то в вашем коде:

-(NSStrng*)nextImageFromXML:(NSUInteger)count
{
   // Somewhere you've already parsed the XML into an Array
   return [xmlArray objectAtIndex:count];
}

Ярлык будет просто ...

 nextImageURL = [NSString stringWithFormat:@"http://www.pictureshostedhere.com/%@",[xmlArray objectAtIndex:onImageCount]]; // Where xmlArray returns the appropriate string
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...