UIActionSheet in NativeScript 1.7
UIActionSheet in NativeScript 1.7
我使用ns1.7,我试图调用UIActionSheet。nsapi已经有了dialog .action(),它类似于UIActionSheet,除了它没有破坏性按钮。所以我想尝试使用本地ActionSheet,我已经成功了:
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);
}
然而,我不知道如何实现回调(这是UIActionSheetDelegate我猜)响应什么用户点击。有一个功能在iOS API称为actionSheet:clickedButtonAtIndex
,但在我不知道如何通过javascript(或typescript)调用它。任何形式的帮助都是感激的。
非常感谢。
从Objective-C到JavaScript的NativeScript封送(数据转换)示例代码可以在此链接
找到基本上,为了实现你的委托,你需要这样做:var UIActionSheetDelegate = UIActionSheet.extend({
clickedButtonAtIndex(buttonAtIndex) {
// clickedButtonAtIndex code implementation here
}
}, {
protocols: [UIActionSheetDelegate]
});
我找到了另一种方法来实现这一点,并通过使用UIAlertController作为UIActionSheet自iOS 8.3以来已被弃用而成功。这是我所做的:
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);
相关文章:
- Node.js's Buffer.writeFloatBE in Javascript
- Setting default onclick behavior for <img> tag in gene
- Lucene Search in Alfresco
- grep in JQuery to C#
- write HTML in JavaScript
- jQuery setTimeOut: in for-loop
- SetTimeout and clearTimeout in Javascript
- lightbox in html 5 and javascript
- NativeScript nativeescapet谷歌地图sdk不令人惊叹
- 是否可以使用NativeScript使用Sqlite数据库
- HTMLInputElement in IE7
- Mongodb$in以与数组中相同的顺序获取结果
- element.dataset in Internet Explorer
- 如何在NativeScript中从列表中删除项目时设置动画
- jQuery parent() in table
- Instagram oauth flow in angularjs
- In循环的In运算符前后
- 如何下载图像并将其显示在NativeScript应用程序中
- Paho MQTT in NativeScript
- UIActionSheet in NativeScript 1.7