Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/473.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript NativeScript 1.7中的UIActionSheet_Javascript_Ios_Nativescript - Fatal编程技术网

Javascript NativeScript 1.7中的UIActionSheet

Javascript NativeScript 1.7中的UIActionSheet,javascript,ios,nativescript,Javascript,Ios,Nativescript,我正在使用NS1.7,我正在尝试调用UIActionSheet。NS API已经有了类似于UIActionSheet的dialogs.action(),只是它没有破坏性按钮。因此,我想尝试使用本机操作表,我已经成功: export function editTap(args: GestureEventData) { var obj = <any>args.object; var actionSheet = new UIActionSheet(); actionShe

我正在使用NS1.7,我正在尝试调用UIActionSheet。NS API已经有了类似于UIActionSheet的dialogs.action(),只是它没有破坏性按钮。因此,我想尝试使用本机操作表,我已经成功:

export function editTap(args: GestureEventData) {
   var obj = <any>args.object;
   var actionSheet = new UIActionSheet();
   actionSheet.addButtonWithTitle("Edit");
   actionSheet.addButtonWithTitle("Delete");
   actionSheet.addButtonWithTitle("Cancel");
   actionSheet.cancelButtonIndex = actionSheet.numberOfButtons - 1;
   actionSheet.destructiveButtonIndex = actionSheet.numberOfButtons - 2;
   actionSheet.showFromRectInViewAnimated(obj.page._nativeView.frame, obj.ios, true);
}
导出函数editTap(args:GestureEventData){ var obj=args.object; var actionSheet=新的UIActionSheet(); actionSheet.addButtonWithTitle(“编辑”); actionSheet.addButtonWithTitle(“删除”); actionSheet.addButtonWithTitle(“取消”); actionSheet.cancelButtonIndex=actionSheet.numberOfButtons-1; actionSheet.destructiveButtonIndex=actionSheet.numberOfButtons-2; actionSheet.showFromRectInViewAnimated(对象页.\u nativeView.frame,obj.ios,true); } 但是,我不知道如何实现响应用户单击内容的回调(我想这是UIActionSheetDelegate)。iOS API中有一个名为
actionSheet:ClickedButtonIndex
的函数,但我不知道如何通过javascript(或typescript)调用它。感谢您的任何帮助


非常感谢。

可以找到Objective-C到JavaScript的NativeScript编组(数据转换)示例代码

基本上,实现委托所需的是:

var UIActionSheetDelegate = UIActionSheet.extend({
    clickedButtonAtIndex(buttonAtIndex) {
        // clickedButtonAtIndex code implementation here
    }
}, {
    protocols: [UIActionSheetDelegate]
});

可以找到Objective-C到JavaScript的NativeScript封送(数据转换)示例代码

基本上,实现委托所需的是:

var UIActionSheetDelegate = UIActionSheet.extend({
    clickedButtonAtIndex(buttonAtIndex) {
        // clickedButtonAtIndex code implementation here
    }
}, {
    protocols: [UIActionSheetDelegate]
});

我找到了另一种实现方法,并成功地使用UIAlertController,因为自iOS 8.3以来,UIActionSheet已被弃用。这就是我所做的:

    var alertController = UIAlertController.alertControllerWithTitleMessagePreferredStyle("title", "message", UIAlertControllerStyle.UIAlertControllerStyleActionSheet);
    var editAction = UIAlertAction.actionWithTitleStyleHandler("Edit", UIAlertActionStyle.UIAlertActionStyleDefault, (arg: UIAlertAction) => {
        //code implementation here
    });
    var deleteAction = UIAlertAction.actionWithTitleStyleHandler("Delete", UIAlertActionStyle.UIAlertActionStyleDestructive, (arg: UIAlertAction) => {
        //code implementation here
    });
    var cancelAction = UIAlertAction.actionWithTitleStyleHandler("Cancel", UIAlertActionStyle.UIAlertActionStyleCancel, (arg: UIAlertAction) => {
        //code implementation here
    });

    alertController.addAction(editAction);
    alertController.addAction(deleteAction);
    alertController.addAction(cancelAction);
    var currentPage = topmost().currentPage;
    var viewController: UIViewController = currentPage.ios;
    viewController.presentModalViewControllerAnimated(alertController, true);

我找到了另一种实现方法,并成功地使用UIAlertController,因为自iOS 8.3以来,UIActionSheet已被弃用。这就是我所做的:

    var alertController = UIAlertController.alertControllerWithTitleMessagePreferredStyle("title", "message", UIAlertControllerStyle.UIAlertControllerStyleActionSheet);
    var editAction = UIAlertAction.actionWithTitleStyleHandler("Edit", UIAlertActionStyle.UIAlertActionStyleDefault, (arg: UIAlertAction) => {
        //code implementation here
    });
    var deleteAction = UIAlertAction.actionWithTitleStyleHandler("Delete", UIAlertActionStyle.UIAlertActionStyleDestructive, (arg: UIAlertAction) => {
        //code implementation here
    });
    var cancelAction = UIAlertAction.actionWithTitleStyleHandler("Cancel", UIAlertActionStyle.UIAlertActionStyleCancel, (arg: UIAlertAction) => {
        //code implementation here
    });

    alertController.addAction(editAction);
    alertController.addAction(deleteAction);
    alertController.addAction(cancelAction);
    var currentPage = topmost().currentPage;
    var viewController: UIViewController = currentPage.ios;
    viewController.presentModalViewControllerAnimated(alertController, true);

当我尝试您的解决方案时,出现了一个错误<代码>协议“未定义”不是协议…。然而,我发现了另一种方法,即使用UIAlertController,因为UIActionSheet自iOS 8.3以来已被弃用。无论如何,谢谢你,特别是Obj-C到JS转换的链接。当我尝试你的解决方案时,出现了一个错误
协议“未定义”不是协议…
。然而,我发现了另一种方法,即使用UIAlertController,因为UIActionSheet自iOS 8.3以来已被弃用。无论如何,谢谢你,特别是Obj-C到JS转换的链接。