JSPatch解析

本文介绍了一种使用JavaScript桥接技术来实现iOS中UITableView的方法。通过定义JSViewController及JSTableViewController类,实现了按钮点击后展示包含20条数据的TableView,并对单元格点击弹出警告框进行了响应。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 1 defineClass('JPViewController', {
 2   handleBtn: function(sender) {
 3     var tableViewCtrl = JPTableViewController.alloc().init()
 4     self.navigationController().pushViewController_animated(tableViewCtrl, YES)
 5   }
 6 })
 7 
 8 defineClass('JPTableViewController : UITableViewController <UIAlertViewDelegate>', ['data'], {
 9   dataSource: function() {
10     var data = self.data();
11     if (data) return data;
12     var data = [];
13     for (var i = 0; i < 20; i ++) {
14       data.push("cell from js " + i);
15     }
16     self.setData(data)
17     return data;
18   },
19   numberOfSectionsInTableView: function(tableView) {
20     return 1;
21   },
22   tableView_numberOfRowsInSection: function(tableView, section) {
23     return self.dataSource().length;
24   },
25   tableView_cellForRowAtIndexPath: function(tableView, indexPath) {
26     var cell = tableView.dequeueReusableCellWithIdentifier("cell") 
27     if (!cell) {
28       cell = require('UITableViewCell').alloc().initWithStyle_reuseIdentifier(0, "cell")
29     }
30     cell.textLabel().setText(self.dataSource()[indexPath.row()])
31     return cell
32   },
33   tableView_heightForRowAtIndexPath: function(tableView, indexPath) {
34     return 60
35   },
36   tableView_didSelectRowAtIndexPath: function(tableView, indexPath) {
37      var alertView = require('UIAlertView').alloc().initWithTitle_message_delegate_cancelButtonTitle_otherButtonTitles("Alert",self.dataSource()[indexPath.row()], self, "OK",  null);
38      alertView.show()
39   },
40   alertView_willDismissWithButtonIndex: function(alertView, idx) {
41     console.log('click btn ' + alertView.buttonTitleAtIndex(idx).toJS())
42   }
43 })
;(function(){try{\ndefineClass('JPViewController', {\n  handleBtn: function(sender) {\n    var tableViewCtrl = JPTableViewController.__c(\"alloc\")().__c(\"init\")()\n    self.__c(\"navigationController\")().__c(\"pushViewController_animated\")(tableViewCtrl, YES)\n  }\n})\n\ndefineClass('JPTableViewController : UITableViewController <UIAlertViewDelegate>', ['data'], {\n  dataSource: function() {\n    var data = self.__c(\"data\")();\n    if (data) return data;\n    var data = [];\n    for (var i = 0; i < 20; i ++) {\n      data.__c(\"push\")(\"cell from js \" + i);\n    }\n    self.__c(\"setData\")(data)\n    return data;\n  },\n  numberOfSectionsInTableView: function(tableView) {\n    return 1;\n  },\n  tableView_numberOfRowsInSection: function(tableView, section) {\n    return self.__c(\"dataSource\")().length;\n  },\n  tableView_cellForRowAtIndexPath: function(tableView, indexPath) {\n    var cell = tableView.__c(\"dequeueReusableCellWithIdentifier\")(\"cell\") \n    if (!cell) {\n      cell = require('UITableViewCell').__c(\"alloc\")().__c(\"initWithStyle"

  

转载于:https://www.cnblogs.com/studyNT/p/7224605.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值