JSPatch寫UITableView

為了學(xué)習(xí)和熟練JSPatch語(yǔ)法,所以嘗試寫一個(gè)簡(jiǎn)單的UITableView視圖
1.動(dòng)態(tài)添加 Property
2.struct變量替換
3.NSArray的使用
4.for循環(huán)的不同.
5.打印console.log()
6.require('UIColor,UIView,NSURL,NSURLRequest,UIFont,UILabel'); 導(dǎo)入頭文件.
7.添加Protocol
8.常量和枚舉

require('NSMutableArray,UITableView,UIView,NSString,UIColor,UITableViewCell');
defineClass("ViewController : UIViewController<UITableViewDelegate,UITableViewDataSource>",['data','tableView'], {
            //實(shí)例方法
            viewDidLoad: function()
            {
            self.super().viewDidLoad()
            console.log(self.dataArray());
            self.setTableView(UITableView.alloc().initWithFrame_style({x:0,y:0,width:self.view().frame().width,height:self.view().frame().height},0));
            self.tableView().setDataSource(self);
            self.tableView().setDelegate(self);
//            self.tableView().setSeparatorStyle(0);
            self.tableView().setTableFooterView(UIView.new());
            self.tableView().setEstimatedRowHeight(40);
            self.tableView().setBackgroundColor(UIColor.yellowColor());
            self.view().addSubview(self.tableView());
            },
            
            dataArray: function()
            {
            var data = self.data();
            if(data) return data;
            var data = NSMutableArray.array();
            console.log("444");
            for (var i = 0; i < 14; i++) {
            var string = NSString.stringWithFormat("JSPatch == %@", i);
            data.addObject(string);
            }
            return data;
            },
            
            tableView_numberOfRowsInSection: function(tableView,section)
            {
            return self.dataArray().count();
            },
            
            tableView_heightForRowAtIndexPath: function(tableView, indexPath) {
            return 60
            },
            
            tableView_cellForRowAtIndexPath: function(tableView,indexPath)
            {
            var cellID = "name";
            var cell = tableView.dequeueReusableCellWithIdentifier(cellID);
            console.log("22222")
            if (!cell) {
            cell = UITableViewCell.alloc().initWithStyle_reuseIdentifier(3, cellID);
            }
            cell.textLabel().setText(self.dataArray().objectAtIndex(indexPath.row()));
            return cell;
            },
            
    },
    {
    //類方法
    });
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容