0

it is a Single View Application, and I just add a button above it when I click the button, it will show the key board. and I can't auto release TSAlertView in onBtn function. Who can tell me why, I am really confused.

- (void)viewDidLoad
{
    [super viewDidLoad];
    UIButton *btn  = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(30, 30, 100., 50);
    [btn setTitle:@"Test" forState:UIControlStateNormal];
    [btn addTarget:self action:(@selector(onBtn:)) forControlEvents: UIControlEventTouchUpInside];
    [btn setBackgroundColor:UIColor.greenColor];
    [self.view addSubview:btn];
}

-(void)onBtn:(id)sender{
    TSAlertView* av = [[TSAlertView alloc] init];
    av.title = @"Test";
    av.message = @"This is a test";
    [av addButtonWithTitle:@"cancel"];
    [av addButtonWithTitle:@"rename"];
    av.style =TSAlertViewStyleInput;
    av.buttonLayout = TSAlertViewButtonLayoutNormal;
    av.usesMessageTextView =NO;
    av.width = 0.0;
    av.maxHeight = 0.0;
    [av show];
}

enter image description here

Jane_Meng
  • 749
  • 1
  • 9
  • 18

2 Answers2

2

You set the AlertView's style to Input, it'll set it as the first responder and show keyboard.

av.style =TSAlertViewStyleInput;

Try another style. ;)

Kjuly
  • 34,476
  • 22
  • 104
  • 118
  • thanks for your suggestion. I find in TSAlertView, it resign text field FirstResponder. While now the problem is when click the button, it don't pop up the alert view, it just show the keyboard. – Jane_Meng Nov 28 '11 at 03:06
  • 1
    @Jane_Meng I tried the Demo the author gave, even comment out the resignFirstResponder is OK. The key one is `av.style = _hasInputFieldSwitch.on ? TSAlertViewStyleInput : TSAlertViewStyleNormal;`. If you turn on the `InputFieldSwitch`, it'll use TSAlertViewStyleInput and show keyboard, other wise, just show alertView as normal(In this case, use style:`TSAlertViewStyleNormal`). – Kjuly Nov 28 '11 at 03:29
  • BTW, you can download it and test yourself. ;) – Kjuly Nov 28 '11 at 03:31
  • Yes, you are right, thanks very much. Now I know why it show the keyboard. But when I click the button, I don't pop up the alertView. and I have no idea about this. Do you have any ideas? – Jane_Meng Nov 28 '11 at 03:59
  • Hi @Jane_Meng, what have you changed in code? Maybe you can print a log in `onBtn:` to show if it is called. Then make sure you do call `[av show];` to show the alert view when the button clicked. – Kjuly Nov 28 '11 at 04:12
  • hi, the OnBtn: is called. and after click test button, it also print following logs: TSAlertView: TSAlertOverlayWindow dealloc|| TSAlertView: TSAlertViewController dealloc || TSAlertView: TSAlertOverlayWindow dealloc. But the alertView never pop up – Jane_Meng Nov 28 '11 at 04:51
  • @Jane_Meng have you changed the code? Remember you can show the alertView with keyboard before. Can you paste you new code? – Kjuly Nov 28 '11 at 05:05
  • hi @Kjuly, it always only shows the keyboard, no alertView, please refer to attachment picture. – Jane_Meng Nov 28 '11 at 05:28
  • hi @Kjuly, I have resolve the problem. I go into my projects build settings. Search for automatic reference counting. Once I find it set the value to "NO". then re-build, it is OK. I don't know why, but now it work correctly. – Jane_Meng Nov 28 '11 at 05:42
  • @Jane_Meng, Cheers! But I think issue still exists, maybe you delloc the alertView as soon as it shown(just a guess). `ARC is done by the compiler and should be thought of as a wizard or helper that checks all of your code and inserts the correct retain and release statements for you`, I'm not familiar with it, but you can refer to some docs on the ARC by yourself. :) – Kjuly Nov 28 '11 at 06:57
1

I haven't used the TSAlertView but after browsing through the code, you try a hack. After you call show, try resigning the first responder:

[av show];
[av.inputTextField resignFirstResponder];

This may or may not work. If not and you really need the keyboard hidden you might want to modify the code regarding the notifications in the TSAlrtView class itself.

TigerCoding
  • 8,710
  • 10
  • 47
  • 72