SigAbort when no text and button click


#1

I thought this was supposed to avoid a crash when no text was entered and the button was pressed?

  • (void)addTask:(id)sender
    {
    NSString *t = [taskField text];
    if ([t isEqualToString:@" “]) {
    return;
    }
    [tasks addObject:t];
    [taskTable reloadData];
    [taskField setText:@”"];
    [taskField resignFirstResponder];

    }

Thanks,
Harry


#2

I thought this would work, but no. I need to disable the button before addTask() is called?

  • (void)addTask:(id)sender
    {
    NSString *t = [taskField text];
    if ([t isEqualToString:@""]) {
    [insertButton setEnabled:NO];
    return;
    }
    [insertButton setEnabled:YES];
    [tasks addObject:t];
    [taskTable reloadData];
    [taskField setText:@""];
    [taskField resignFirstResponder];

    }


#3

I think I should have done the code slightly differently. Try this:

- (void)addTask:(id)sender { NSString *t = [taskField text]; if ([t length] == 0) { return; } [tasks addObject:t]; [taskTable reloadData]; [taskField setText:@""]; [taskField resignFirstResponder]; }
(The setEnabled: stuff is yours, right? I think it is flawed, but the change to length == 0 may fix your sigabort.)