开发者

How to update the password label before resetting it?

I want to mimic the iphone unlock password dialog. I created four labels and after user has entered the fourth number, I check the correctness. If correct, I'll dismiss the dialog. If incorrect, I'll clear the input boxes and let user retry. I call updateText when a button is pressed.

- (void) updateText{

pw1.text = [self.enteredPwd objectAtIndex:0];
pw2.text = [self.enteredPwd objectAtIndex:1];
pw3.text = [self.enteredPwd objectAtIndex:2];
pw4.text = [self.enteredPwd objectAtIndex:3];

if (currentIndex > 3) {
    // check pwd
    [self checkPwd];
}
}
- (IBAction)pwBtnUp:(id)sender {

UIButton *btn = (UIButton*)sender;

[self.enteredPwd insertObject:[NSString stringWithFormat:@"%d", btn.tag] atIndex:currentIndex++];
[self updateText];
}

But I've got one problem: the fourth charater never had a chance to display. No matter correct or not, the dialog got dismissed/cleared right after the last button is t开发者_如何学编程apped.

I have no clue how to fix this. I even tried to update the label in a UIView Animation with the checkPwd called in the completion block, but no luck.

Please give me some suggestion how to fix this. The apple's dialog has about .5 second pause before clearing the labels.

Thanks

Leo


Couldn't you just use a NSTimer or a selector which runs after an delay? If pwBtnUp is the function which is invoked when the user taps a number just check if it is the 4th number then perform an function after some delay that hides or clear the fields.


Rather than using an NSTimer just insert a delay:

[self performSelector:@selector(checkPwd) withObject:nil afterDelay:0.5];

BTW, your code seems slightly redundant. Why are you updating all the text fields/labels each time a new button is pressed? This is not necessary, if the fields already contain a character. But maybe that's beside the point.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜