C++ 将UIAlertView上按下的按钮的结果返回到C++;方法
我需要调用一个uiAlctVIEW,以显示一个C++文件。根据按下的按钮,我需要返回一个BoL到C++类本身(BoOL反过来得到返回,并在别处使用)。我想知道一些关于如何返回结果到C++类的建议。我已经假定不能将C++类设置为UIActuvVIEW的委托,所以我需要通过某种方式将哪个按钮压到C++类。C++ 将UIAlertView上按下的按钮的结果返回到C++;方法,c++,objective-c,uialertview,C++,Objective C,Uialertview,我需要调用一个uiAlctVIEW,以显示一个C++文件。根据按下的按钮,我需要返回一个BoL到C++类本身(BoOL反过来得到返回,并在别处使用)。我想知道一些关于如何返回结果到C++类的建议。我已经假定不能将C++类设置为UIActuvVIEW的委托,所以我需要通过某种方式将哪个按钮压到C++类。 这是C++的示例函数调用(它是C++类,但编译为Objtovi:C: bool CPlatform::WarningMessage(const wchar_t* message) { //
这是C++的示例函数调用(它是C++类,但编译为Objtovi:C:
bool CPlatform::WarningMessage(const wchar_t* message)
{
// Some functions to convert message to an NSString* wNSString
MessagePopUp *message = [[MessagePopUp alloc] init];
[message showPopUpWithMessage:wNSString];
// This function should return true if OK is pressed, or False if Cancel is pressed.
}
然后,我有一个简单的类来显示警报
@interface MessagePopUp : NSObject <UIAlertViewDelegate> {
BOOL OKPressed;
}
- (void) showPopUpWithMessage:(NSString*)message;
@end
@implementation MessagePopUp
- (void) showPopUpWithMessage:(NSString*)message
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Warning" message:message delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
[alert show];
[alert release];
}
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
// the user clicked one of the OK/Cancel buttons
if (buttonIndex == 0)
{
NSLog(@"ok");
OKPressed = true;
}
else
{
NSLog(@"cancel");
OKPressed = false;
}
}
@end
@interface MessagePopUp:NSObject{
布尔奥克;
}
-(void)showPopUpWithMessage:(NSString*)消息;
@结束
@实现消息弹出窗口
-(void)showPopUpWithMessage:(NSString*)消息
{
UIAlertView*alert=[[UIAlertView alloc]initWithTitle:@“警告”消息:消息委托:自取消按钮:@“取消”其他按钮:@“确定”,无];
[警报显示];
[警报发布];
}
-(无效)alertView:(UIAlertView*)操作表单击按钮索引:(NSInteger)按钮索引{
//用户单击了确定/取消按钮之一
如果(按钮索引==0)
{
NSLog(@“正常”);
OKPressed=true;
}
其他的
{
NSLog(@“取消”);
OKPressed=false;
}
}
@结束
你能推荐一种方法,我可以把结果/ OkPress返回到C++函数吗?
谢谢如果您可以混合使用这两种语言,那么您可以使用objective-c概念,称为NSNotificationCenter 此代码将侦听器添加到“显示警报”类的父级: 然后,在alert view类中,您可以执行以下操作来发送消息:
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
// the user clicked one of the OK/Cancel buttons
if (buttonIndex == 0)
{
// Not sure, but I think buttonIndex == 0 is actually cancel.
NSLog(@"cancel");
self.OKPressed = false;
[[NSNotificationCenter defaultCenter] postNotificationName:@"alertViewClicked"
object:self];
} else {
self.OKPressed = false;
[[NSNotificationCenter defaultCenter] postNotificationName:@"alertViewClicked"
object:self];
}
}
然后,您只需从父类/C++访问布尔属性。您不可能轻松做到这一点,因为思考代码流会告诉您这一点 问题是运行循环,为了显示AlctVIEW(即在调用<代码> [警报显示] < /代码>),需要返回控制到iOS,这意味着C++函数
更好的方法是在C++<代码> cStutoS/<代码>类中接受回调并在C++代码中接受<代码> Objult>代码> BoOL,在您的<代码> CLICKEDButoAtTutoals< /Cord>委托方法> < /P>中,这不能解决@ PayIO请求帮助的同步性/阻塞问题。感谢罗杰。我同意,最好是尝试建立一个阻塞的UIActuvVIEW。我试图不给CSTORE类做太多修改(在那个特定函数调用之外),但是我会尝试像你建议的那样回调。任何人都有一个想法来定义C++中的回调?
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
// the user clicked one of the OK/Cancel buttons
if (buttonIndex == 0)
{
// Not sure, but I think buttonIndex == 0 is actually cancel.
NSLog(@"cancel");
self.OKPressed = false;
[[NSNotificationCenter defaultCenter] postNotificationName:@"alertViewClicked"
object:self];
} else {
self.OKPressed = false;
[[NSNotificationCenter defaultCenter] postNotificationName:@"alertViewClicked"
object:self];
}
}