-1

我想在 for 语句中包含更多语句。现在我这样做:

for (UIImageView* img in imageArray){
for (UITextField* txt in messagename){

}}

...但是以这种方式它多次重复代码,所以我尝试了这个:

for (UIImageView* img in imageArray)||(UITextField* txt in messagename)

但它不起作用!

编辑:

for (UIImageView* img in imageArray)||(UITextField* txt in messagename) {


    img.hidden = YES;

    CABasicAnimation* anim = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    [anim setToValue:[NSNumber numberWithFloat:0.0f]];
    [anim setFromValue:[NSNumber numberWithDouble:M_PI/80]]; // rotation angle
    [anim setDuration:0.1];
    [anim setRepeatCount:NSUIntegerMax];
    [anim setAutoreverses:YES];
    //[img.layer addAnimation:anim forKey:@"iconShake"];


    UIImage *tmpImage = [UIImage imageNamed:@"message small type 2.png"];
    CGRect cellRectangle;
    cellRectangle = CGRectMake(20, img.frame.origin.y + 45, 710, 60);
    UIImageView *dragger = [[Draggable alloc] initWithFrame:cellRectangle];
    [dragger setImage:tmpImage];
    [dragger setUserInteractionEnabled:YES];

    [self.view addSubview:dragger];

    [wobbleImage addObject: dragger];

    Draggable* sharedSingleton = [Draggable sharedManagerDraggable];
    sharedSingleton.namePassedToDraggable = txt.text;

    dragger.tag = img.tag;

    dragger.layer.cornerRadius = 10; // this value vary as per your desire
    dragger.clipsToBounds = YES;

    [dragger.layer addAnimation:anim forKey:@"iconShake"];

}
4

1 回答 1

2

如果两个数组总是有相同数量的对象,那么您可能想要的是:

NSUInteger count = imageArray.count;
for (NSUInteger i = 0; i < count; i++) {
    UIImageView *img = imageArray[i];
    UITextField *txt = messagename[i];

    // rest of code
}
于 2012-12-14T17:17:28.387 回答