I would like to insert an NSTimer delay within a method and was wondering how to go about doing this. I’ve bolded where I would like to put the delay timer.
here’s my code so far:
- (void) buttonPressed:(UIButton*) sender {
for(int i = 0;i < [categoryBtnImages count]; i++)
{
UIButton *but = (UIButton *)[catButtonArray objectAtIndex:i];
if(but != sender)
{
[but setImage:[UIImage imageNamed:[categoryBtnImages objectAtIndex:i]] forState:UIControlStateNormal];
// but.selected = !but.selected;
}
}
buttonCat = (UIButton *)sender;
int tagOfButton = buttonCat.tag - 2;
if (tagOfButton == -2 ){
tagOfButton = 8;
}
[buttonCat setImage:[UIImage imageNamed:[categoryBtnImagesSel objectAtIndex:tagOfButton]] forState:UIControlStateNormal];
I would like to put the delay here then run the rest of the code, but all from within this method.
if ([sender.titleLabel.text isEqualToString:@"Button 0"]) {
[self foodCatSort:nil];
[self.tableView reloadData];
}
if ([sender.titleLabel.text isEqualToString:@"Button 1"]) {
[self healthCatSort:nil];
[self.tableView reloadData];
}
if ([sender.titleLabel.text isEqualToString:@"Button 2"]) {
[self shoppingCatSort:nil];
[self.tableView reloadData];
}
}
FYI the reason I want to do this is because a button is pressed which reloads the table and the button state image changes. I would like the user to see the uibutton image change first then reload the table. I was thinking a delay would solve this.
If you just need a delay you dont need a
NSTimer.Use
performselector: withObject: afterDelay:instead.Something like this: