lundi 29 juin 2015

Programaticaly Click 10 UIButtons one after another in UIScrollView


I am developing one control where 10 UIButtons are added in UIScrollView. Now i have a requirement to click every Button one after another after some delay. can you all guide me how to do that?

here is the code what i have done.

in viewcontroller.h file

@property (weak) IBOutlet UIScrollView *mapScrollView;
@property (strong) UIButton *addContactIcon;

in viewcontroller.m file

// Set up ScrollView with UIButtons
NSUInteger xPosition = 1;
NSUInteger countIndex = 0;
for (ContactModule *sortedContacts in _distanceList) {

    _addContactIcon = [[UIButton alloc] initWithFrame:CGRectMake(xPosition, 7, 30, 30)];
    _addContactIcon.tag = countIndex;
    [_addContactIcon addTarget:self action:@selector(mapsScrollButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    _addContactIcon.layer.cornerRadius = 2.0;
    _addContactIcon.clipsToBounds = YES;
    [_addContactIcon setBackgroundImage:[UIImage imageWithContentsOfFile:dataPath] forState:UIControlStateNormal];
    [_addContactIcon setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_mapScrollView addSubview:_addContactIcon];
    xPosition += _addContactIcon.frame.size.width + 2;
    countIndex = countIndex + 1;
}
_mapScrollView.contentSize = CGSizeMake(30 * _distanceList.count + 34, 40);
[_mapScrollView setShowsHorizontalScrollIndicator:NO];

Here is the Button Click Method For Every Button:

- (void)mapsScrollButtonClicked:(UIButton *)clickButton {

    // Set Annotation Callout
    [_mapsView selectAnnotation:[_mapsView.annotations objectAtIndex:clickButton.tag] animated:YES];
}

Now the requirement is I want to call Action Method for Every UIButtons in UIScrollview. for that i am doing something wrong below. help me with that:

for(NSUInteger count=0; count<[_distanceList count];count++)    {

            [UIView animateWithDuration:0.4
                              delay:0.8
                            options:0
                         animations:^{
                             [_addContactIcon sendActionsForControlEvents:UIControlEventTouchUpInside];
                         } completion:nil];
 }


Aucun commentaire:

Enregistrer un commentaire