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中 帮助
答案 0 :(得分: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];
答案 1 :(得分: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];
分解,以便更容易调试并了解正在发生的事情。
答案 2 :(得分: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];
答案 3 :(得分: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];
答案 4 :(得分:-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];