OGeek|极客世界-中国程序员成长平台

标题: iOS 程序流程 - 等待用户输入 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 14:01
标题: iOS 程序流程 - 等待用户输入

我是 iOS 编程新手,正在尝试找出如何中断程序流以等待响应。

基本上我想从我的应用程序发送一封电子邮件,并提供数据是什么,我想提示用户添加更多信息。

即:

- (IBAction)sendEmailid)sender {

MyManagedObject *myObj = nil;

//Retrieve from the database.
NSManagedObjectContext *ctx = [self managedObjectContext];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName"MyManagedObject" inManagedObjectContext:ctx];
[request setEntity:entity];

NSError *error;
NSArray *array = [ctx executeFetchRequest:request error:&error];
NSUInteger count = [array count]; // May be 0 if the object has been deleted.
if (count > 0) {
    myObj = (MyManagedObject *)[array objectAtIndex:0];
}

 //Recipients
NSArray *toRecipents = [[NSArray alloc]init];
// Email Subject
NSString *emailTitle = [@"Report for Month of: " stringByAppendingString: dateString] ;
// Email Content
NSString *messageBody = @"";
if(myObj != nil) {
    if (myObj.firstName) {
        messageBody = [messageBody stringByAppendingString:[@"\nHello " stringByAppendingString: myObj.firstName]];
        toRecipents = [NSArray arrayWithObject:myObj.emailAddress];
    }
}
messageBody = [messageBody stringByAppendingString"\n\nBelow is my text...."];
messageBody = [messageBody stringByAppendingString:[@"\nMore Information...: " stringByAppendingString: myObj.moreInfo]];

NSString *addInfo = OPEN WINDOW FOR USER TO ADD INFO

if (addInfo != nil) {
messageBody = [messageBody stringByAppendingString:[@"\nAdditional Information...: " stringByAppendingString: addInfo]];
}

... send the email
}

我不确定在没有回调的情况下这是否可行。基本上我想打断流程,放置一个覆盖并等待它在完成电子邮件之前关闭......



Best Answer-推荐答案


据我了解,您尝试做的是显示自定义对话框或警报 View ,并且仅在其返回值上,代码应该进一步执行。

可以这么说,如果您在 UITextView 内显示 UIAlertView 以添加更多信息,则应将 sendEmail 方法移至回调alertview 的按钮。同样,如果您要使用一些自定义对话框,那么您应该在自定义对话框中编写一个回调到主窗口,然后在该回调中,您应该编写用于发送电子邮件的代码。

我认为,像这样的回调机制是您选择的唯一解决方案,如果您希望所有内容都写在同一个代码块中,那么您可以使用 blocks in objective-c

关于iOS 程序流程 - 等待用户输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18564623/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4