Objective c Cocoa touch如何在while循环中运行UIAlertView
我有一个int,其中有人设置有多少拼写被称为Objective c Cocoa touch如何在while循环中运行UIAlertView,objective-c,cocoa-touch,while-loop,uialertview,Objective C,Cocoa Touch,While Loop,Uialertview,我有一个int,其中有人设置有多少拼写被称为samount,还有一个int被称为amountdone,它们都被设置为0,就像这样NSInteger samount=0; NSInteger amountdone=0在开始处。我有一个按钮,当它被点击时,它调用Startese方法。代码是 - (IBAction)Startest:(id)sender { UIAlertView *amount = [[UIAlertView alloc] initWithTitle:@"Amount" me
samount
,还有一个int被称为amountdone
,它们都被设置为0,就像这样NSInteger samount=0;
NSInteger amountdone=0代码>在开始处。我有一个按钮,当它被点击时,它调用Startese方法。代码是
- (IBAction)Startest:(id)sender {
UIAlertView *amount = [[UIAlertView alloc] initWithTitle:@"Amount" message:@"How much spellings are there" delegate:self cancelButtonTitle:@"That amount" otherButtonTitles:nil];
[amount setAlertViewStyle:UIAlertViewStylePlainTextInput];
[[amount textFieldAtIndex:0] setKeyboardType:UIKeyboardTypeNumberPad];
[amount setTag: 0];
[amount show];
}
我需要一个UIAlertView来显示它自己,然后将它的文本添加到一个数组中,我得到了alertView ClickedButtonIndex
void这样工作
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch (alertView.tag)
{
case 0: /* amount alert */
{
samount = [[alertView textFieldAtIndex:0]text];
UIAlertView *spellings = [[UIAlertView alloc]initWithTitle:@"Enter Spelling " message:@"Pleaseenter ONE of the spellings" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[spellings setTag:1];
[spellings setAlertViewStyle:UIAlertViewStylePlainTextInput];
[spellings show];
}
break;
case 1: /* Spellings alert*/{
while (amountdone < samount) {
amountdone = amountdone + 1;
self.myarry = [[alertView textFieldAtIndex:0]text];
}
}
break;
}
}
`
-(无效)alertView:(UIAlertView*)alertView单击按钮索引:(NSInteger)按钮索引
{
开关(alertView.tag)
{
案例0:/*金额警报*/
{
samount=[[alertView textFieldAtIndex:0]文本];
UIAlertView*拼写=[[UIAlertView alloc]initWithTitle:@“输入拼写”消息:@“请输入其中一种拼写”委托:自取消按钮:@“确定”其他按钮:无];
[拼写设置标签:1];
[拼写设置AlertViewStyle:UIAlertViewStylePlainTextInput];
[拼写显示];
}
打破
案例1:/*拼写提示*/{
while(amountdone
它第一次工作,但一旦while循环激活,它就会冻结应用程序。是否有人知道如何修复此创建方法来创建和启动您的alertView和ClickedButtonIndex:method call after delay
[self performSelector:@selector(yourMethodForLaunchingAlertView:)
withObject:objectOrNill
afterDelay:0.5];
希望能有所帮助。好吧,它被锁定的原因是amountdone
除了初始化0之外从未被设置为任何其他值,因此amountdone
可能总是true
,因此您的while
循环将永远持续下去
假设什么时候设置amountdone
编辑
我认为您不需要while
循环。根据你所拥有的
while (amountdone < samount) {
amountdone = amountdone + 1;
self.myarry = [[alertView textFieldAtIndex:0]text];
}
while(amountdone
虽然
循环不提供任何值,但它也可能是一个if
条件,因为您正在反复设置相同的内容(将NSString
设置为NSArray
也没有意义)
我认为是时候退一步,重新评估你正在解决的问题和你的方法了。如果您描述用例/业务需求,或许我可以提供帮助。Baiscly,我需要UIAlertView显示一定次数并将其文本设置为数组。很好,但我如何重复一定次数取决于您的需求,如果您想每0.5秒调用一次,您可以通过for循环执行,例如:for(int i=0;i)此代码仅保持运行警报视图,而不等待用户解除警报,这会导致问题。您应该显示一个警报,当用户解除警报时,您应该显示另一个警报,依此类推。实现此目的的最佳方法是创建变量,该变量将记录您希望警报视图显示的次数以及用户何时解除警报E解除警报,如果不是零,则显示另一个警报。