- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好,想用 super 循环创建自定义 tableViewCell。问题是,我不知道该怎么做。我试过用一个 swift 类来实现它:
细胞.swift
import UIKit
public class MyCell: UITableViewCell{//UICollectionViewCell {
public var imgUser:UIImageView = UIImageView()
public var labUerName:UILabel = UILabel()
public var labMessage:UILabel = UILabel()
public var labTime:UILabel = UILabel()
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
NSLog("la");
imgUser.backgroundColor = UIColor.blue
imgUser.translatesAutoresizingMaskIntoConstraints = false
labUerName.translatesAutoresizingMaskIntoConstraints = false
labMessage.translatesAutoresizingMaskIntoConstraints = false
labTime.translatesAutoresizingMaskIntoConstraints = false
labUerName.frame = CGRect(x: 5, y: 5, width: 70, height: 30)
contentView.addSubview(imgUser)
contentView.addSubview(labUerName)
contentView.addSubview(labMessage)
contentView.addSubview(labTime)
}
public required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
public func setName(txt: String){
labUerName.text = txt
}
}
在我的 tableview Controller 中:
(function (container) {
var UIScreen = require('UIKit/UIScreen'),
UIColor = require('UIKit/UIColor'),
UITableView = require('UIKit/UITableView'),
UITableViewCell = require('UIKit/UITableViewCell'),
NSIndexPath = require('Foundation').NSIndexPath,
UITableViewStyleGrouped = require('UIKit').UITableViewStyleGrouped,
UITableViewCellStyleSubtitle = require('UIKit').UITableViewCellStyleSubtitle,
UITableViewCellAccessoryDisclosureIndicator = require('UIKit').UITableViewCellAccessoryDisclosureIndicator;
// Grabs the JSON-file from app/lib/static/data.json
var file = Ti.Filesystem.getFile(Ti.Filesystem.getResourcesDirectory() + 'static/data.json');
var users = JSON.parse(file.read().text).users;
var Cell = require('MyFramework/MyCell'); // HERE IS MY CUSTOM CELL
// Subclass delegate + data source
var TableViewDataSourceAndDelegate = require('subclasses/tableviewdatasourcedelegate');
// Create + configure tableView
var tableView = UITableView.alloc().initWithFrameStyle(UIScreen.mainScreen.bounds, UITableViewStyleGrouped);
var dataSourceDelegate = new TableViewDataSourceAndDelegate();
dataSourceDelegate.numberOfSections = function(tableView) {
return 1;
};
dataSourceDelegate.numberOfRows = function(tableView, section) {
return users.length;
};
dataSourceDelegate.titleForHeader = function(tableView, section) {
return 'Available users: ' + users.length;
};
dataSourceDelegate.heightForRow = function(tableView, indexPath) {
return 44;
};
dataSourceDelegate.cellForRow = function(tableView, indexPath) {
var user = users[indexPath.row];
var cell = tableView.dequeueReusableCellWithIdentifierForIndexPath('hyperloop_cell', indexPath);
cell.setName('abc');
return cell;
};
dataSourceDelegate.didSelectRowAtIndexPath = function(tableView, indexPath) {
alert('Call me maybe: ' + users[indexPath.row].phone);
tableView.deselectRowAtIndexPathAnimated(indexPath, true);
};
// Assign delegate + data source
tableView.registerClassForCellReuseIdentifier(Cell.self, "hyperloop_cell");
tableView.setDelegate(dataSourceDelegate);
tableView.setDataSource(dataSourceDelegate);
container.add(tableView);
})($.tableview_container);
不知道怎么用好。有人能帮助我吗 ?谢谢
最佳答案
不确定为什么它不起作用,但是看起来您没有做任何没有 super 循环就无法完成的事情...为什么不使用 Appcelerator 创建您自己的 tableview 单元格/行布局?
关于swift - 使用 Appcelerator Hyperloop 自定义 TableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44974350/
正在关注 https://github.com/barriehadfield/hyperloop_devise_tutorial当您从 Rails 控制台调用 Hyperloop::Applicati
我正在尝试 Hyperloop。我正在尝试运行项目中的自定义 swift 脚本(如示例所示)。 这是我的快速代码: import UIKit public class MySwiftCode : NS
我已经按照此处的说明从 master 下载了最新的 SDK:http://builds.appcelerator.com/#master 我还从这里下载了最新的 Hyperloop http://la
我需要开发一个带有视频 session 的应用程序 (iOS),有一个名为 TokBox 的库,但只能与 xcode(我的意思是 native 代码)一起使用,所以我想知道 hyperloop 是否可
我尝试在非 Alloy 项目中使用 Hyperloop,但显然它不起作用(如果我错了,请纠正我)。传统的 CommonJS 项目不能使用 Hyperloop 有什么技术原因吗? 最佳答案 使用 ti
我正在尝试在我的 appcelerator 项目中使用 Google-Mobile-Ads-SDK,因为 ti.admob ( https://github.com/appcelerator-modu
我不确定我在这里做错了什么,但是当我运行我的应用程序以在 Appcelerator Hyperloop iOS 中对图像进行灰度化时,我收到运行时错误。该错误是在尝试运行 CGBitmapContex
我正在尝试在我的 Titanium 应用程序中使用 hyperloop 监控 UIScreenCapturedDidChangeNotification 的屏幕录制状态。我已经尝试了一段时间,但找不到
您好,想用 super 循环创建自定义 tableViewCell。问题是,我不知道该怎么做。我试过用一个 swift 类来实现它: 细胞.swift import UIKit public clas
我有一个简单的 Swift 类,它在创建它的 XCode 8.1 项目中运行良好(该类中有更多内容,但为了简洁起见,示例被删减了)。 import UIKit import AVFoundation
我一直在尝试(我希望如此)直接在钛项目中(使用 SDK 7.0.1.GA 和 hyperloop 3)的简单 Android hyperloop 代码。 var sysProp = require('
关于如何使用 Hyperloop 在 JavaScript 中require cocoapods 的问题:了解应该传递给 require 语句的字符串的最可靠方法是什么椰子?例如 Ti docs在他们
我正在尝试在 Appcelerator Hyperloop 中做最简单的事情来定义/创建我自己的类,但这导致我的构建失败(无法为模拟器或设备构建)并出现构建时错误控制台。 我刚刚开始一个新的空白 Al
我是一名优秀的程序员,十分优秀!