Showing posts with label BOOL. Show all posts
Showing posts with label BOOL. Show all posts

Monday, February 14, 2011

UISearchDisplayController with No Results

Don't know what it is, but I just can't make UISearchDisplayDelegate shouldReloadTableForSearchString method work the way I read the documentation:
You might implement this method if you want to perform an asynchronous search. You would initiate the search in this method, then return NO. You would reload the table when you have results.

Tuesday, July 6, 2010

UITextField textFieldShouldBeginEditing called twice in iOS4

When you tap UITextField, you get two textFieldShouldBeginEditing calls. This looks like a bug in initial iOS4 release. Workaround is to use a BOOL flag to decide what you should do with that call:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    if (self.allowEdit)
    {
        [self askUser];
        return NO;
    }
    return YES;
}

- (void)askUser
{
    if (self.alertVisible)
        return;    
    self.alertVisible = YES;
    
    UIAlertView *alert =
    [[UIAlertView alloc] initWithTitle:@"Please verify"
                               message:@"Do you want to edit?"
                              delegate:self
                     cancelButtonTitle:@"Cancel"
                     otherButtonTitles:@"Yes",
     nil];
    [alert show];
    [alert release];
}

- (void)alertView:(UIAlertView *)alertView
    clickedButtonAtIndex:(NSInteger)buttonIndex
{
    self.alertVisible = NO;
    if (buttonIndex == 1)
        [self doSomething];
}
The bug will (should) be fixed in some future iOS4 release, so it's more safe to isolate your work-around inside your own routines as much as possible to minimize possible unwanted side-effects.