我只是出于好奇而感到奇怪,为什么是C时间结构
struct tm
Run Code Online (Sandbox Code Playgroud)
用作此而不是用typedef.这样我总是需要编写struct tm,以获得正确的代码.很多结构都是"类型确定的",为什么不这个呢?
我的 C API 定义如下:
typedef enum Foo {
A = 0,
B = 1
} Foo;
typedef struct Bar {
int a;
Foo foo;
} Bar;
Run Code Online (Sandbox Code Playgroud)
如何Foo在 Swift 中直接使用枚举?我知道,我可以这样做var data: Foo = A,但我不喜欢这种语法,其中A似乎是一些全局变量。
我宁愿拥有var data: Foo = Foo.A或类似的标准枚举。有办法吗?
是否可以在NSNotificationCenter中使用不同名称链接一个方法?
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(Finish:) name:@"FinishDownload_data1" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(Finish:) name:@"FinishDownload_data2" object:nil];
Run Code Online (Sandbox Code Playgroud)
......等
在我的代码中,当我调用通知时,我在userInfo Dictionary中传递其名称和其他一些参数.
我想要这个的原因是因为我有运行时生成的事件.它们具有相同的主体,但仅在保存目标方面有所不同,具体取决于_data#.我希望每个下载都在同一个地方处理.
问题是,如果我使用它,则不会调用通知.
我以UITableViewController编程方式创建viewDidLoad():
resultsController = UITableViewController(style: UITableViewStyle.plain)
resultsController.tableView.register(MyTableCellTableViewCell.self, forCellReuseIdentifier: "userFoundCell")
resultsController.tableView.dataSource = self
resultsController.tableView.delegate = self
Run Code Online (Sandbox Code Playgroud)
但是,当我以后这样做
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell: MyTableCellTableViewCell? = tableView.dequeueReusableCell(withIdentifier: "userFoundCell", for: indexPath) as? MyTableCellTableViewCell
if (cell == nil){
cell = MyTableCellTableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "userFoundCell")
}
cell!.lblTmp!.text = "test"
return cell!
}
Run Code Online (Sandbox Code Playgroud)
cell 从来没有,我测试过它
代码崩溃:
致命错误:在单元格中展开可选值时意外发现nil!.lblTmp!.text ="test"
我MyTableCellTableViewCell看起来像这样
class MyTableCellTableViewCell: UITableViewCell {
@IBOutlet var lblTmp: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
}
override …Run Code Online (Sandbox Code Playgroud) 我有这个代码来获取表格单元格
func getCell(_ tableView: UITableView) -> UITableViewCell? {
var cell:UITableViewCell? = tableView.dequeueReusableCell(withIdentifier: CELL_REUSE_ID)
if (cell == nil)
{
//init and configure the cell
cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: CELL_REUSE_ID)
let selectedView:UIView = UIView(frame: CGRect(x: 0, y: 0, width: cell!.frame.size.width, height: cell!.frame.size.height))
selectedView.backgroundColor = UIColor.black.withAlphaComponent(0.3)
let layer = selectedView.layer
layer.borderColor = UIColor.blue.cgColor
layer.borderWidth = getCellBorderWidth();
layer.cornerRadius = getCellCornerRadius();
layer.backgroundColor = UIColor.blue.cgColor
cell!.selectedBackgroundView = selectedView
}
return cell
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell:UITableViewCell? …Run Code Online (Sandbox Code Playgroud) 我目前有这个代码:
var dic = [String: [String]]()
if (dic.index(forKey: key) != nil){
dic[key]?.append(m)
}
else {
dic[key] = [m]
}
Run Code Online (Sandbox Code Playgroud)
但是,在dic.index(forKey: key)和dic[key]?.append(m)我计算了两次密钥。
有没有可能做这样的事情?:
var dictKeyVal = &dic[key]
if (dictKeyVal != nil) {
dictKeyVal?.append(m)
}
else {
dic[key] = [m]
}
Run Code Online (Sandbox Code Playgroud)
如果没有键,我在键或 nil 处获取对数组的引用
这是我的代码:
<html>
<head>
<title>
</title>
</head>
<body>
<?php
$username = $_POST['username'];
$password = $_POST['password'];
if (($username=="x")AND($password=="y"))
{
echo "You are logged in as".$username.";
}
?>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我得到一个解析错误:
解析错误:语法错误,意外的文件结束,期望变量(T_VARIABLE)或$ {(T_DOLLAR_OPEN_CURLY_BRACES)或第17行的{$(T_CURLY_OPEN)
swift ×4
ios ×3
c ×2
uitableview ×2
arrays ×1
dictionary ×1
enums ×1
objective-c ×1
php ×1
struct ×1
typedef ×1