小编h4l*_*abs的帖子

计算两个日期之间的天数?

如何计算两个日期之间的天数?在下面的代码中,我应该得到小时数,这意味着我只需要除以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

time go

16
推荐指数
2
解决办法
1万
查看次数

导航栏中带有范围按钮的 iOS11 SearchController

在此输入图像描述

在 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

ios swift ios11

5
推荐指数
1
解决办法
2596
查看次数

使用来自clang的@import?

我想用终端上的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)

clang ios

3
推荐指数
1
解决办法
1260
查看次数

从xib在自定义单元格上设置IBAction?

我在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)

uitableview ios ios6

1
推荐指数
1
解决办法
1617
查看次数

动态更改商店的分拣机?

我有一个商店,我想预定几套分拣机.对于第一个,我通过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)

sencha-touch sencha-touch-2

1
推荐指数
1
解决办法
4764
查看次数

标签 统计

ios ×3

clang ×1

go ×1

ios11 ×1

ios6 ×1

sencha-touch ×1

sencha-touch-2 ×1

swift ×1

time ×1

uitableview ×1