有没有办法在结束函数之前等待或暂停直到子视图被释放?
在我的一个函数中,通过按下按钮,我添加一个子视图,然后在该子视图中的文本视图中键入文本。然后我想将该文本带回原始函数并将其保存到变量中。问题是我有多个按钮都使用此子视图但具有不同的变量,因此它不能在发布后为所有按钮运行相同的函数。
main view controller
-(IBAction)Button1Pressed:(id)sender{
NSString *TempString;
TextEditViewController* TextViewController = [[TextEditViewController alloc] initWithNibName:@"TextEditViewController" bundle:[NSBundle mainBundle]];
[self.view addSubview:TextViewController.view];
/* wait for subview to be released */
SpecificString = TempString;
}
-(IBAction)Button2Pressed:(id)sender{
NSString *TempString;
TextEditViewController* TextViewController = [[TextEditViewController alloc] initWithNibName:@"TextEditViewController" bundle:[NSBundle mainBundle]];
[self.view addSubview:TextViewController.view];
/* wait for subview to be released */
DifferentSpecificString = TempString;
}
New view controller
-(IBAction)doneButtonPressed:(id)sender{
TempString = textView.text;
[self.view removeFromSuperview];
[self.view release];
}
In one of my functions, from a button press, I am adding a subview, then typing text to a textview in that subview. I want to then take that text back to the original function and save it to a variable. The problem is that I have multiple buttons that all use this subview but with different variables, so it can't just run the same function for all of them after it's released.
main view controller
-(IBAction)Button1Pressed:(id)sender{
NSString *TempString;
TextEditViewController* TextViewController = [[TextEditViewController alloc] initWithNibName:@"TextEditViewController" bundle:[NSBundle mainBundle]];
[self.view addSubview:TextViewController.view];
/* wait for subview to be released */
SpecificString = TempString;
}
-(IBAction)Button2Pressed:(id)sender{
NSString *TempString;
TextEditViewController* TextViewController = [[TextEditViewController alloc] initWithNibName:@"TextEditViewController" bundle:[NSBundle mainBundle]];
[self.view addSubview:TextViewController.view];
/* wait for subview to be released */
DifferentSpecificString = TempString;
}
New view controller
-(IBAction)doneButtonPressed:(id)sender{
TempString = textView.text;
[self.view removeFromSuperview];
[self.view release];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是代表的魔力最能发挥的作用。
您还需要在主视图控制器的 .h(接口)文件中声明您的委托协议。 这里有一个教程为您详细解释了这个概念< /a>.
我希望这对你有帮助!
This is what the magic of delegates is best for.
You also need to declare your delegate protocol in your main view controller's .h (interface) file. Here's a tutorial that explains this concept a bit more for you.
I hope this helps you out!