如何计算两个日期之间的天数?在下面的代码中,我应该得到小时数,这意味着我只需要除以24.但是,我得到的结果是-44929.000000.我只想回来一两天,所以我希望24或48小时.
package main
import (
"fmt"
"time"
)
func main() {
timeFormat := "2006-01-02"
t, _ := time.Parse(timeFormat, "2014-12-28")
fmt.Println(t)
// duration := time.Since(t)
duration := time.Now().Sub(t)
fmt.Printf("%f", duration.Hours())
}
Run Code Online (Sandbox Code Playgroud)
这是可执行的Go代码:http://play.golang.org/p/1MV6wnLVKh
在 iOS 11 中,您可以使用几行代码将 UISearchController 放置在导航栏中。
我在 ViewController.swift 中设置了所有内容。
func setupNavBar() {
navigationController?.navigationBar.prefersLargeTitles = true
let searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = wordViewController
searchController.searchBar.scopeButtonTitles = ["French", "English"]
searchController.searchBar.delegate = wordViewController
navigationItem.searchController = searchController
// Make searchbar persistent
navigationItem.hidesSearchBarWhenScrolling = false
}
Run Code Online (Sandbox Code Playgroud)
在我的代表中,搜索会正确触发和过滤。但是,如果我单击任一范围按钮,它们就会消失。该委托方法永远不会被调用。(按范围过滤尚未实际实现)
extension WordViewController: UISearchBarDelegate {
func searchBar(_ searchBar: UISearchBar, selectedScopeButtonIndexDidChange selectedScope: Int) {
if let searchText = searchBar.text {
print("Scoped changed: \(searchText)")
filteredWordList = wordList.filter({$0.contains(searchText)})
}
}
}
Run Code Online (Sandbox Code Playgroud)
完整源代码位于 Github 上:
https://github.com/melling/ios_topics/tree/master/NavBarSearch https://github.com/melling/ios_topics/tree/master/NavBarSearch/NavBarSearch
我想用终端上的Sublime和clang编写一些代码.如何在clang中使用新模块(@import)语法?我尝试添加-fmodules标志,但它不起作用.启用模块后,我是否也可以省略-framework Foundation标志?
clang -fmodules -framework Foundation test.mm; ./a.out
Run Code Online (Sandbox Code Playgroud)
小测试文件:
#import <stdio.h>
// #import <Foundation/Foundation.h>
@import Foundation;
/*
clang -fmodules -framework Foundation test.mm; ./a.out
*/
int main(int argc, char const *argv[])
{
NSString *hello = @"Hello";
printf("%s\n", "hello world");
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我在xib中创建了一个自定义单元格(在iOS6中使用故事板,但为单元格创建了单独的xib),现在我正在尝试将我的扬声器按钮连接到我的UITableViewController sublcass中的IBAction.

我在viewDidLoad中注册了我的单元格:
[self.tableView registerNib:[UINib nibWithNibName:@"MissedWordTableCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MissedWordCell"];
Run Code Online (Sandbox Code Playgroud)
我尝试了几种不同的方法来添加目标.例如,在我的tableView:cellForRowAtIndexPath中,我尝试直接添加目标.
static NSString *CellIdentifier = @"MissedWordCell";
MissedQuestionEntity *missedQuestion;
// forIndexPath: is iOS6
MissedWordTableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Add target here? Didn't work. @selector(playWordAction) or @selector(playWordAction:)
// [cell.playAudioBtn addTarget:self action:@selector(playWordAction) forControlEvents:UIControlEventTouchUpInside];
Run Code Online (Sandbox Code Playgroud)
我还尝试在我的自定义单元格xib中将文件所有者设置为我的表视图控制器,但仍然无效.
这是我的错误消息:
2013-07-30 07:47:15.833 Spanish[69420:c07] *** Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[__NSArrayI doIt]: unrecognized selector sent to instance
0xec34430'
*** First throw call stack:
(0x231e012 0x172de7e 0x23a94bd 0x230dbbc 0x230d94e 0x1741705 0x6752c0 0x675258 0x736021 0x73657f 0x7356e8
0x6a4cef …Run Code Online (Sandbox Code Playgroud) 我有一个商店,我想预定几套分拣机.对于第一个,我通过band rank,lastName定义了排序顺序.

{
property: 'rank',
direction: 'ASC'
},
{
property: 'lastName',
direction: 'ASC'
}
Run Code Online (Sandbox Code Playgroud)
对于我的第二个,我希望分拣机是年,乐队,lastName:
{
property: 'year',
direction: 'ASC'
},
{
property: 'band',
direction: 'ASC'
},
{
property: 'lastName',
direction: 'ASC'
}
Run Code Online (Sandbox Code Playgroud)
如何在我的商店换掉第一台分拣机,然后根据需要换回?
这是代码的其余部分:
BandMemberStore.js:
Ext.define('Sencha.store.BandMemberStore', {
extend: 'Ext.data.Store',
requires: [],
config: {
model: 'Sencha.model.BandMember',
autoLoad: true,
defaultRootProperty: 'items',
proxy: {
type: 'ajax',
url: 'bands.json',
reader: {
type: 'json',
rootProperty: 'items'
}
},
sorters : [
{
property: 'rank',
direction: 'ASC'
},
{
property: 'lastName',
direction: 'ASC'
}
] …Run Code Online (Sandbox Code Playgroud)