1

私のアプリでは、次のようにNSTimerを使用してUIButtonの画像を変更しているコンテキストがあります

 [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(LoadImageToTheAdButton) userInfo:nil repeats:YES];


-(void)LoadImageToTheAdButton
{
     NSString *strPath = [arrPaths objectAtIndex:0];
        strPath = [strPath stringByAppendingPathComponent:@"Folder"];
        strPath = [strPath stringByAppendingPathComponent:[arrAdImgNames objectAtIndex:intAdImgIndex]];
        UIImage *imgForAdBtn = [[UIImage alloc]initWithContentsOfFile:strPath];
        [btnAd setBackgroundImage:imgForAdBtn forState:UIControlStateNormal];

        if(intAdImgIndex < [arrAdImgNames count]-1)
        {
            intAdImgIndex++;
        }
        else
        {
            intAdImgIndex = 0;
        }
}

ボタンをクリックすると*ボタンにどの画像が設定されているかを知る必要があります。つまり、画像名が必要です*

その画像に基づいていくつかのリンクを読み込んでいるので、それが必要です。

どうすればそれを行うことができますか?

前もって感謝します

4

2 に答える 2

0

現在ボタンに設定されている画像の名前を取得することはできません。取得できるのは、画像を参照するメモリ アドレスだけです。良い代替手段は、buttons タグ プロパティを使用して、画像名を含む配列のインデックスを指定することです。例えば:

myArray = [[NSArray alloc] initWithObjects:@"something.png",@"somethingElse.png",@"etc.png", nil];

- (void)myMethod:(UIButton *)sender
{
    NSString *imageNameSelected = [myArray objectAtIndex:sender.tag];
}

したがって、この例では、ボタンの画像を「something.png」に設定すると、ボタンのタグ プロパティを「0」に設定するか、「somethingElse.png」の場合は「1」に設定します。

于 2012-10-19T09:19:26.240 に答える
0

任意のビューで setAccessibility* プロパティを試してください。これらはとても役に立ちます。アプリでこのプロパティを使用して画像名を取得します。

于 2012-10-19T10:37:02.267 に答える