0
 UIAlertView *myAlert=[[UIAlertView alloc]
initWithTitle:@"Logging in" message:@"you are a member in our website \nWelcome Dear  %@ ",UserName.text
            delegate:self
            cancelButtonTitle:@"Done"
            otherButtonTitles:nil];

这段代码对我显示错误,因为我输入了字符串变量,它是一个名为“用户名”的文本字段的文本

那我怎么能把这条线分开呢?

initWithTitle:@"Logging in" message:@"you are a member in our website \nWelcome Dear %@ ",UserName.text delegate:self

因为错误在这里显示在delegate HELP这个词中

4

5 回答 5

1

使用以下格式:

UIAlertView *myAlert=[[UIAlertView alloc]
initWithTitle:@"Logging in" message:[NSString stringWithFormat:@"you are a member in our website \nWelcome Dear  %@ ",UserName.text]
            delegate:self
            cancelButtonTitle:@"Done"
            otherButtonTitles:nil];
于 2012-09-12T10:42:48.103 回答
0

试试这个:

NSString *alertstr=[NSString stringWithFormat:@"you are a member in our website \nWelcome Dear  %@",UserName.text];
UIAlertView *myAlert=[[UIAlertView alloc]
                          initWithTitle:@"Logging in" message:alertstr
                          delegate:self
                          cancelButtonTitle:@"Done"
                          otherButtonTitles:nil];
于 2014-01-22T06:33:26.497 回答
0

重组它如下:

NSString *psMsg = [NSString stringFromFormat: @"you are a member in our website \nWelcome Dear  %@ ", UserName.text, nil];
UIAlertView *myAlert=[[UIAlertView alloc]
    initWithTitle:@"Logging in" message:psMsg
    delegate:self cancelButtonTitle:@"Done"
    otherButtonTitles:nil];

分解事物,以便更容易调试和理解正在发生的事情。

于 2012-09-11T04:53:10.250 回答
0

这是因为您没有创建字符串作为参数。

您可以通过在行中声明您的字符串(选项 1)或将字符串创建移到 UIAlert 视图之外(选项 2)来解决此问题。

我喜欢对所有字符串使用本地化字符串(选项 3),因为它有助于从代码中获取字符串,允许字符串重用并有助于国际化。

选项1:

UIAlertView *myAlert=[[UIAlertView alloc]
                        initWithTitle:@"Logging in" 
                        message:[NSString stringWithFormat:@"you are a member in our website \nWelcome Dear  %@ ",UserName.text]
                        delegate:self
                        cancelButtonTitle:@"Done"
                        otherButtonTitles:nil];

选项 2:

NSString *alertstr=[NSString stringWithFormat:@"you are a member in our website \nWelcome Dear  %@",UserName.text];

UIAlertView *myAlert=[[UIAlertView alloc]
                          initWithTitle:@"Logging in" message:alertstr
                          delegate:self
                          cancelButtonTitle:@"Done"
                          otherButtonTitles:nil];

选项 3:

UIAlertView *myAlert=[[UIAlertView alloc]
                        initWithTitle:NSLocalizedString(@"Login-title", nil) 
                        message:NSLocalizedString(@"Login-message",nil)
                        delegate:self
                        cancelButtonTitle:NSLocalizedString(@"Done", nil)
                        otherButtonTitles:nil];
于 2014-02-24T12:15:14.290 回答
-3

我认为这是唯一的方法,当您显示该消息时无需显示登录。

UIAlertView *myAlert=[[UIAlertView alloc]initWithTitle:@"you are a member in our website Welcome Dear " message:mytext.text
                      delegate:self
                      cancelButtonTitle:@"Done"
                      otherButtonTitles:nil];

[myAlert show];
[myAlert release];
于 2012-09-11T07:04:08.653 回答