Ios 当我按下Xcode上的按钮时,如何从数组循环中取出当前整数值?

Ios 当我按下Xcode上的按钮时,如何从数组循环中取出当前整数值?,ios,objective-c,int,ibaction,Ios,Objective C,Int,Ibaction,我需要获取mtype的当前值并将其向前传递给Mselect,以便向前推送的图像与动画中旋转的图像相同 下面是代码示例 - (void)viewDidLoad { //Array to hold Images NSMutableArray *imageArray = [[NSMutableArray alloc] initWithCapacity:Mush_Count]; for (mtype = 1; mtype < Mush_Count; mtype++)

我需要获取mtype的当前值并将其向前传递给Mselect,以便向前推送的图像与动画中旋转的图像相同

下面是代码示例

- (void)viewDidLoad
{

    //Array to hold  Images
    NSMutableArray *imageArray = [[NSMutableArray alloc] initWithCapacity:Mush_Count];

    for (mtype = 1; mtype < Mush_Count; mtype++)
    {
        [imageArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"Mush%i.png", mtype]]];
        //make button

        SelectBt.imageView.animationImages = [NSArray arrayWithArray:imageArray];
        SelectBt.imageView.animationDuration = 5;
        [SelectBt.imageView startAnimating];

        Mselect = mtype;

    }
}    
-(IBAction)Selection:(id)sender{
    [self Placement];
}

-(void)Placement{
    if (Place1Occ == NO) {
        [self Place1];
    }
}
-(void)Place1{
    if (Place1Occ == NO) {
        Place1.image =[UIImage imageNamed:[NSString stringWithFormat:@"Mush%i.png", Mselect]];
    Place1Occ = YES;
    }
}
-(void)viewDidLoad
{
//用于保存图像的数组
NSMutableArray*imageArray=[[NSMutableArray alloc]initWithCapacity:Mush_Count];
对于(mtype=1;mtype
动画循环很好,图像的选择工作正常,但它没有选择当前在屏幕上的图像,而是选择阵列上的最后一个图像


有什么建议吗?

SelectBT是UIButton的子类吗?如果是,是来自您的IBAction的(id)发件人吗

如果是这样的话,您可以通过调用
sender.imageView.image

另一方面,objective-C约定是将类名大写,但在实例开始时使用小写字母,例如
ClassName*instanceOfClassName
,如果不遵守该约定,您可能会在这里受到抨击

更新

可以将imageArray插入类变量或属性中吗?它已经包含所有完全加载的UIImages,您可以通过调用
[imageArray objectAtIndex:i]

然后,您只需跟踪哪个数字索引面向您的用户,或者他们点击哪个索引并拉取相应的图像

如果您想让我们进一步解释,请随时发布您的整个课程

for (mtype = 1; mtype < Mush_Count; mtype++)
{
    [imageArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"Mush%i.png", mtype]]];
}

据我所知,你不能直接获得动画的当前帧-你必须在启动动画时创建一个计时器,并让它计算帧数(通过增加您的
Mselect
值。然后使用该值加载当前图像

mtype是局部变量吗?Mselect如何?它们都是int,并且都是局部变量?当我单击时,我真的只需要mtype的值。当它在图像中旋转时,mtype=1-9,我需要该数字为我的UIImage视图指定适当的值。对于某些原因它给出了数组的最后一个值,该值最终分配了数组中的最后一个图像。无论我何时按下按钮。感谢提示。SelectBT是UIButtonWesome,您也必须将sender强制转换为SelectBT。
UIImage*targetImage=(SelectBT*)sender.imageview.image;
当我将其更改为上面的代码时,它只给了我数组中的第一个图像。我在-(void)Place1{Place1.image=selectBt.imageview.image;}上更改了代码好的,这听起来更好,因为我需要索引号来进行后续编码。如果你不介意的话,请解释更多我还在学习。你说要发布我的整个课程?我试图一次编写一段代码,这样我就不会迷路,所以现在我只想让我的前7幅图像按照我的选择工作。这是我的原创我计划,但我担心与循环分离的计时器会导致它给我一个不同的图像,而不是当前正在翻转按钮的图像。我创建了计时器,但我将if语句编码错误。如何计算按钮上的帧数,使其与Mselect值相对应。我无法将Uibutton值放在e if语句int numFrames=[imageArray count];在计时器中:Mselect++;if(Mselect>(numFrames-1))Mselect=0;谢谢Dav,它不起作用。我将稍后在mronign中重试。我整晚都在忙这个。我的下一个问题是,为什么不跳过计时器并将image arraycount的值分配给Mselect,但这也不起作用。使用此设置,它会一直分配数组中的第一个图像。我已经仔细检查了我一遍又一遍地修改代码,看看我是否遗漏了导致这种情况的原因,但我找不到。让计时器工作了,现在我只需要匹配帧速率。
    SelectBt.imageView.animationImages = [NSArray arrayWithArray:imageArray];
    SelectBt.imageView.animationDuration = 5;
    [SelectBt.imageView startAnimating];