我问了一个关于Javascript的问题,这指向Window对象关于"this"指向Window对象.
这是源代码
var archive = function(){}
archive.prototype.action = {
test: function(callback){
callback();
},
test2: function(){
console.log(this);
}
}
var oArchive = new archive();
oArchive.action.test(oArchive.action.test2);
Run Code Online (Sandbox Code Playgroud)
Tim Down写道"但是该函数随后使用callback()调用,这意味着它不被称为方法,因此这是全局对象".
通过实际名称调用函数和源代码中显示的callback()之间有什么区别?
当test2中的console.log(this)指向Window时,它是如何指向Window的.
我正在阅读"开始iPhone开发"一书并在第9章中停留.我花了几个小时试图调试此错误而无济于事:
2010-05-01 19:27:51.361 Nav2[4113:20b] *** Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit/UIKit-984.38/UITableView.m:4709
2010-05-01 19:27:51.362 Nav2[4113:20b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
2010-05-01 19:27:51.364 Nav2[4113:20b] Stack: (
...
)
Run Code Online (Sandbox Code Playgroud)
我不是在寻求这本书的帮助,而是关于如何调试此错误的提示.我能确定哪种cellForRowAtIndexPath方法是问题吗?以及如何检查类型?或者我应该看看其他什么?
编辑:根据要求,两个可疑方法的代码:
-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *RootViewControllerCell = @"RootViewControllerCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:RootViewControllerCell];
if (cell == nil) {
cell == [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:RootViewControllerCell] autorelease];
}
NSUInteger row = [indexPath row];
SecondLevelViewController …Run Code Online (Sandbox Code Playgroud) 我知道在活动中调用finish()会产生与用户单击Back按钮相同的结果; Home按钮有类似的东西吗?(想要在某些动作后自动显示主屏幕).
编辑:另外,我会赞赏菜单和搜索按钮.
谢谢!
我想产生一个变量这是两个字符的串联,例如从"p30s4""p28s4"到"p30s4 p28s4"去了.我尝试了猫和粘贴,如下所示.两者都返回空变量.我究竟做错了什么?
> blah = c("p30s4","p28s4")
> blah
[1] "p30s4" "p28s4"
> foo = cat(blah)
p30s4 p28s4
> foo
NULL
> foo = paste(cat(blah))
p30s4 p28s4
> foo
character(0)
Run Code Online (Sandbox Code Playgroud) 我第一次来这里,因为我终于开始学习编程了.无论如何,我只想在这里每秒打印一次纳秒的时间,我有这个:
#!/usr/bin/env bash
while true;
do
date=(date +%N) ;
echo $date ;
sleep 1 ;
done
Run Code Online (Sandbox Code Playgroud)
现在,这只是产生一串日期,这不是我想要的.怎么了?我的学习相当混乱,所以如果真的很简单,我希望你能原谅我.此外,我确实设法很好地解决了这个问题:
while true ; do date +%N ; sleep 1 ; done
Run Code Online (Sandbox Code Playgroud)
但这显然不适合作为剧本?
编辑,如果有人看到这个:啊,这确实修复了我的错误.我注意到你没有添加; 那是因为我只定义了一个变量吗?另外,你能解释一下$的作用吗?我以为是调用变量.而且我看到上面这行确实可以作为一个剧本; 我曾预计日期的输出不会被放在屏幕上.
有没有办法在Mac OS X屏幕保护程序激活或进入睡眠状态时触发操作(最好使用可可)?
什么是测试2个矩形相交的快速方法?
在互联网上搜索想出了这个一行代码(WOOT!),但我不知道如何把它写在Javascript中,似乎在一个古老的形式C++来编写.
struct
{
LONG left;
LONG top;
LONG right;
LONG bottom;
} RECT;
bool IntersectRect(const RECT * r1, const RECT * r2)
{
return ! ( r2->left > r1->right
|| r2->right < r1->left
|| r2->top > r1->bottom
|| r2->bottom < r1->top
);
}
Run Code Online (Sandbox Code Playgroud) 我有一个我在Qt创建者工作的项目,需要第三方库.我想将标题添加到项目的包含路径中.我该怎么做呢?
我有一些涉及Parallel for循环和添加到List的问题.问题是,相同的代码可能在不同的时间生成不同的输出.我在下面设置了一些测试代码.在这段代码中,我创建了一个包含10,000个int值的List.1/10的值将为0,1/10的值将为1,一直到值的十分之一为9.
设置此List后,我设置了一个Parallel for循环,遍历列表.如果当前数字为0,我将一个值添加到新列表中.Parallel for循环完成后,我输出列表的大小.大小应始终为1,000.大多数时候,给出了正确的答案.但是,我发现有3种可能的错误结果:
doubleList.Add(0.0);doubleList.Add(0.0);给出ArgumentException的消息是: Destination array was not long enough. Check destIndex and length, and the array's lower bounds.
可能导致错误的原因是什么?这是一个.Net错误吗?有什么我可以做的,以防止这种情况发生?
请亲自试用代码.如果您没有收到错误,请尝试几次.另请注意,使用单核机器时可能不会发现任何错误.
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace ParallelTest
{
class Program
{
static void Main(string[] args)
{
List<int> intList = new List<int>();
List<double> doubleList = new List<double>();
for (int i = 0; i < 250; i++)
{
intList.Clear();
doubleList.Clear();
for (int j = 0; j < 10000; j++) …Run Code Online (Sandbox Code Playgroud) 我有一个托管UINavigationController的UIPopoverController,它包含一个小的视图控制器层次结构.
我按照文档和每个视图控制器,我设置了视图的popover-context大小,如下所示:
[self setContentSizeForViewInPopover:CGSizeMake(320, 500)];
Run Code Online (Sandbox Code Playgroud)
(每个控制器的大小不同)
当我在层次结构中向前导航时,这可以正常工作 - 弹出窗口自动动画大小更改以对应于推送的控制器.
但是,当我通过导航栏的"后退"按钮通过视图堆栈"返回"时,弹出窗口不会改变大小 - 它仍然与最深的视图一样大.这似乎对我不利; 我希望popover能够尊重弹出视图堆栈时设置的大小.
我错过了什么吗?
谢谢.
uiviewcontroller uinavigationcontroller uipopovercontroller ios