0

我正在尝试创建一个应用程序,当我按下警报视图打开时,我add button在导航栏上的 table.m 文件中创建。此警报标题存储在数据库中,此标题显示在 UITableView 上。怎么表现?buttonEnter name of alert title.

-(IBAction)Add:(id)sender
{
    UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"GPS Reminder?" message:@"Please Enter Reminder" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];

    text_field = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
    text_field.placeholder=@"Enter Reminder";
    [text_field becomeFirstResponder];
    [text_field setBackgroundColor:[UIColor whiteColor]];
    [myAlertView addSubview:text_field];
    [myAlertView show];

}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
{
     if (buttonIndex == 1) {
        [self validation];

        NSString *str = [NSString stringWithFormat:@"insert into Worklist (userid,worktype) values ('%d','%@')",pkoflist,text_field.text];
        NSLog(@"%@",str);

        [Database executeQuery:str];
        [self initilization];
    }
}
4

3 回答 3

0

首先,您不能对文本字段发出警报。当您单击它时,您可以将其分配给一个按钮。请参阅要制作otherButtonTitles为的代码nil

-(void)method {
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"username" 
                                   message:@"plz enter the corret username" 
                                  delegate:nil 
                         cancelButtonTitle:@"OK"
                         otherButtonTitles: nil];
     [alert show];
     [alert release];
}
于 2013-02-07T07:29:56.013 回答
0

使用 alertViewStyle UIAlertViewStylePlainTextInput

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"title" message:@"message" delegate:self cancelButtonTitle:@"Abort" otherButtonTitles:@"Save", nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert show];

然后在

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
   if (buttonIndex == 1) {
    // get string from textfield
    string = [alertView textFieldAtIndex:0].text;
    // save
    // reload table with saved string
}
于 2013-02-07T11:20:23.477 回答
0

我的 void 方法有错误,我检测到这个.... - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex; {

if (buttonIndex == 1)
{
    if([self validation])
    {
    NSString *str = [NSString stringWithFormat:@"insert into Worklist (userid,worktype) values ('%d','%@')",pkoflist,text_field.text];
    NSLog(@"%@",str);

    [Database executeQuery:str];
    [self initilization];
    }
}

}

于 2013-03-13T07:44:12.503 回答