小编Spe*_*her的帖子

iOS - UITableView无法滚动到底部

我正在iOS中构建一个聊天应用程序但是我在UITableView上显示所有消息时遇到了一些问题.我希望表视图在加载时滚动到底部,以便用户在打开应用程序时可以看到最新消息.

为此,我在刷新数据的函数中添加了此代码:

    NSIndexPath* ipath = [NSIndexPath indexPathForRow: [self.messageOnTimeline numberOfRowsInSection:0]-1 inSection: 0];
    [self.messageOnTimeline scrollToRowAtIndexPath: ipath atScrollPosition: UITableViewScrollPositionTop animated: YES];
Run Code Online (Sandbox Code Playgroud)

这工作正常,直到我在tableview中添加了一个标题.我添加了以下代码,现在加载应用程序时它不会滚动到底部:

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 30)];
    return view;
}
Run Code Online (Sandbox Code Playgroud)

有谁知道为什么?

非常感谢您的帮助

scroll header scrollto uitableview ios

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

在jade中导入CSV/JSON

我使用jade作为静态网站的模板引擎,所以我没有使用任何快速服务器.我想导入一个csv或json文件来加载我的模板中的数据.它可以很容易地使用快速服务器完成,但我不知道没有一个如何做到这一点.

作为临时解决方案,我手动加载数据如下:

- var arr = []
- arr.push(['hello', 'world', 'foo', 'bar'])
- arr.push(['hello1', 'world1', 'foo1', 'bar1'])
- arr.push(['hello2', 'world2', 'foo2', 'bar2'])
- arr.push(['hello3', 'world3', 'foo3', 'bar3'])
- arr.push(['hello4', 'world4', 'foo4', 'bar4'])

- for (var i; i < arr.length; ++i) {
  div
     h1=arr[i][0]
     // some more jade
- }
Run Code Online (Sandbox Code Playgroud)

相反,我正在寻找这样的事情:

- var arr = require('./data.csv')

- for (var i; i < arr.length; ++i) {
  div
     h1=arr[i][0]
     // some more jade
- }
Run Code Online (Sandbox Code Playgroud)

玉有什么办法吗?

非常感谢

node.js pug

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

angularJS - 使用ng-options添加静态选项

我正在使用ng-options在我的角度应用程序中打印表单的所有选项.我直接从我的数据库中获取了值,这给了我一个国家列表:

<select ng-options="country.country for country in countries" ng-model="selectedCountry" ng-change="updateSelectedCountry(selectedCountry)" class="form-control">
Run Code Online (Sandbox Code Playgroud)

这里加载页面时,选择不会显示任何内容,即没有占位符,而我想打印一个静态值,如"任何地方",而不必将其添加到我的"国家/地区"列表中.

我试过这个:

<select ng-options="country.country for country in countries" ng-model="selectedCountry" ng-change="updateSelectedCountry(selectedCountry)" class="form-control">
<option>Anywhere</option>
</select>
Run Code Online (Sandbox Code Playgroud)

但它不起作用

有谁知道如何解决这个问题?

谢谢

javascript angularjs ng-options

7
推荐指数
2
解决办法
3万
查看次数

使用回调对查询中的结果进行排序和限制

使用Mongoose,我想用MongoDB进行查询并命令并限制我得到的结果.我正在使用Node.js这样做,所以我使用回调.

到目前为止,我已经成功订购了我的结果:

  myModel.find({ $query: {}, $orderby: { created_at : -1 }}, function (err, items) {
    callback( null, items )
  });  
Run Code Online (Sandbox Code Playgroud)

如何限制我选择的结果和索引以及我想要获得的项目数?

mongoose mongodb node.js

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

迭代通道发送的所有值,直到它在Go中关闭

我试图了解goroutines和渠道如何运作.我有一个循环向通道发送值,我想迭代通道发送的所有值,直到它关闭.

我在这里写了一个简单的例子:

package main

import (
    "fmt"
)

func pinger(c chan string) {
    for i := 0; i < 3; i++ {
        c <- "ping"
    }
    close(c)
}

func main() {
    var c chan string = make(chan string)

    go pinger(c)

    opened := true
    var msg string

    for opened {
        msg, opened = <-c
        fmt.Println(msg)
    }
}
Run Code Online (Sandbox Code Playgroud)

这给出了预期的结果,但我想知道是否有更短的方法来做到这一点.

非常感谢您的帮助

go

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

无法全球安装快递

我正在尝试全局安装express,但每次运行命令行'npm install -g express'时,我都会收到以下错误消息:

npm http GET https://registry.npmjs.org/express
npm http 200 https://registry.npmjs.org/express
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/express'
npm ERR!  { [Error: EACCES, mkdir '/usr/local/lib/node_modules/express']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/usr/local/lib/node_modules/express',
npm ERR!   fstream_type: 'Directory',
npm ERR!   fstream_path: '/usr/local/lib/node_modules/express',
npm ERR!   fstream_class: 'DirWriter',
npm ERR!   fstream_stack: 
npm ERR!    [ '/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23',
npm ERR!      '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53',
npm ERR!      'Object.oncomplete (fs.js:107:15)' ] }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! System …
Run Code Online (Sandbox Code Playgroud)

terminal install node.js npm express

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

用条件计算json中的项目数

我想计算符合某些条件的JSON项目数组中的项目数.我的数组看起来像这样:

array = [{
            name: 'Bob',
            age: 24
           },
          ....,
          {
            name: 'Mary',
            age: 23
           }]
Run Code Online (Sandbox Code Playgroud)

我试图让表达式像我的数据库请求一样简单优雅,而不是遍历整个数组:

db.myCollection.find({ age: 23 }).count()
Run Code Online (Sandbox Code Playgroud)

有没有最好的做法?我在考虑使用下划线库,但我无法找到我要找的东西.

非常感谢您的帮助.

javascript json angularjs

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

安装Octave时出错

我试图在OS X上安装Octave.执行时brew install octave我收到以下错误:

octave: A LaTeX distribution is required to install.

You can install MacTeX distribution from:
  http://www.tug.org/mactex/

Make sure that "/usr/texbin", or the location you installed it to, is in
your PATH before proceeding.
Run Code Online (Sandbox Code Playgroud)

我下载并安装了MacTeX,但它仍然无法正常工作:(

我怎样才能解决这个问题?

homebrew octave

6
推荐指数
2
解决办法
2008
查看次数

将当前单词的下一个出现位置添加到 VIM 中的选择中

我刚刚从 Sublime text 切换到 MacVim。我在 Sublime 中喜欢的一个有用的快捷方式是 cmd+D,它将当前单词的下一个出现位置添加到选择中。有什么办法可以在 VIM 中获得同等的效果吗?

非常感谢

vim keyboard-shortcuts sublimetext2

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

Octave/Matlab - 无法/绘制数据

我有一个简单的数据文件,如下所示:

data.txt
34.62365962451697,78.0246928153624,0
30.28671076822607,43.89499752400101,0
35.84740876993872,72.90219802708364,0
60.18259938620976,86.30855209546826,1
79.0327360507101,75.3443764369103,1
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用以下代码绘制其数据:

data = load('data.txt');
X = data(:, [1, 2]); y = data(:, 3);

plotData(X, y);

hold on;

xlabel('Exam 1 score')
ylabel('Exam 2 score')

legend('Admitted', 'Not admitted')
hold off;

pause;
Run Code Online (Sandbox Code Playgroud)

但是这给我带来了以下错误:

warning: legend: plot data is empty; setting key labels has no effect
error: legend: subscript indices must be either positive integers less than 2^31 or logicals
Run Code Online (Sandbox Code Playgroud)

没有任何东西被绘制.

我不明白什么是错的.工作目录很好八度.

我怎样才能解决这个问题?

非常感谢

matlab octave

6
推荐指数
3
解决办法
2955
查看次数