我有一个像休息的阵列,
NSArray*array = [NSArray arrayWithObjects:@"1.1 something", @"1.2 something else", @"1.3 out of left field", @"1.4 yet another!", nil];
Run Code Online (Sandbox Code Playgroud)
现在,我有一个像休息一样的字符串,
NSString*str = @"1.3";
Run Code Online (Sandbox Code Playgroud)
现在我将发送str.然后它需要在数组中找到str并且它需要返回该文本找到的对象的索引.我需要索引2的内容必须作为输出.任何人都可以共享代码.谢谢预先.
这个控件有名字吗?或者只是将一堆简单的控件合并在一起?如果是这样,他们有什么控制权?
我在控件上显示上下文相关菜单时遇到问题当选择多行时单击桌面视图.选择单行然后单击控件时,它工作正常.我实现这个的方式如下所示:
-(void)doSingleClick
{
NSLog(@"single clicked");
if([[NSApp currentEvent] modifierFlags] & NSControlKeyMask)
{
NSLog(@"control clicked.......");
[NSMenu popUpContextMenu:[self showContextMenu] withEvent:[NSApp currentEvent] forView:tableView];
return;
}
}
Run Code Online (Sandbox Code Playgroud)
和showContextMenu函数返回一个NSMenu对象.
我这样做是因为我的表视图出于某种奇怪的原因无法识别mouseDown或mouseUp或menuForEvent事件.
上面代码段的问题是,当选择多行并单击控件时,它无法识别控件单击并且不会进入该循环,因此不显示上下文菜单.
请建议我实现这一目标的机制.
谢谢
我想从一个文件或一个objective-c字符串(在代码中)运行一个shell脚本.我还希望将shell脚本的结果存储到变量中.我不希望将shell脚本拆分为参数(例如运行时的setLaunchPath).例如:运行此shell脚本"mount_webdav idisk.mac.com/mac_username/Volumes/mac_username"而不是"/ bin/mount_webdav"然后运行参数.反正有没有这样做?我现在正在使用NSTask,但是当我尝试将参数与它一起使用时,它给我带来了一些错误.这是提出的代码:
(一些.m文件)
NSString *doshellscript(NSString *cmd_launch_path, NSString *first_cmd_pt) {
NSTask *task = [[NSTask alloc] init]; // Make a new task
[task setLaunchPath: cmd_launch_path]; // Tell which command we are running
[task setArguments: [NSArray arrayWithObjects: first_cmd_pt, nil]];
[task setArguments: first_cmd_pt];
NSPipe *pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
[task launch];
NSData *data = [[pipe fileHandleForReading] readDataToEndOfFile];
NSString *string = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
[task release]; //Release the task into the world, thus destroying it.
return string;
}
NSString …
Run Code Online (Sandbox Code Playgroud) 我有一个函数,其中有一个调用函数的循环.
function displayItem(item, isChild)
{
if (isChild)
{
writeOutput('<li>' & item.name & '</li>');
}
else
{
writeOutput('<li>' & item.name);
}
try
{
if (item.hasChild)
{
writeOutput('<ul>');
numberOfItems = item.numChildren;
for (x=1;x LT numberOfItems;x++)
{
displayItem(item.child[x], true);
}
writeOutput('</ul>');
}
}
catch(Exception e){}
writeOutput('</li>');
}
Run Code Online (Sandbox Code Playgroud)
执行该函数后,循环继续执行该执行的x值,而不是从之前的位置开始.
例如:x为3. displayItem传递"item.child [3]"并为true.它通过函数工作,进入循环,执行循环到x = 4,然后退出循环.函数结束并(根据我的理解)返回到x应为3的点.而不是从3中取出,添加一个(使其成为4)然后再次执行循环,它从4中取出(值从"内部"递归地称为循环).
我知道这听起来不连贯,但我想不出任何其他方式来解释它.
有什么我做错了,或者这只是生活中的一个事实,我必须解决一些问题?
更新: 看了更多,看起来好像最早的循环提前退出.使用局部变量'x'修复了计数问题,但是如果查看上一个示例,则循环只退出4.它在条件满足之前离开.有任何想法吗?
@protocol Runnable
- (id<Runnable>) works; //this compiles fine
- (Runnable *) broke; // get a compile error saying Expected ')' before 'Runnable'
@end
Run Code Online (Sandbox Code Playgroud)
我不确定我理解为什么xCode抱怨这- (Runnable *) broke;
条线
我有一个字符串数组:
NSArray *names;
names = [NSArray arrayWithObjects:
@"FirstList",
@"SecondList",
@"ThirdList",
nil];
Run Code Online (Sandbox Code Playgroud)
我正在尝试将此字符串数组的元素分配给字符串变量,如下所示:
NSString *fileName = names[0]; // "Incompatible types in initialization"
Run Code Online (Sandbox Code Playgroud)
或铸造
NSString *fileName = (NSString)names[0]; // "Conversion to non-scalar type requested"
Run Code Online (Sandbox Code Playgroud)
我正在尝试这样做,所以我可以在一个以字符串作为参数的方法中使用该字符串,例如:
NSString *plistPath = [bundle pathForResource:filetName ofType:@"plist"];
Run Code Online (Sandbox Code Playgroud)
有没有办法将字符串数组的元素分配给字符串变量?
names[0]
.但在提出这个问题的时候,它给出了这个问题中提到的错误.如何使用目标c获取当前聚焦的窗口id,返回值应为int,非常感谢帮助!我只需要让以下一行工作
CGImageRef windowImage = CGWindowListCreateImage(CGRectNull, kCGWindowListOptionIncludingWindow, winNum, kCGWindowImageBoundsIgnoreFraming);
Run Code Online (Sandbox Code Playgroud)
但无论我关注哪个窗口,winNum始终为0.
现值是未来付款或一系列未来付款的给定日期的价值,折现以反映货币的时间价值和投资风险等其他因素.现值计算被广泛用于商业和经济学中,以提供在有意义的"喜欢"的基础上比较不同时间的现金流量的方法.
http://en.wikipedia.org/wiki/Present_value
在Objective-C函数中解决这个问题的最佳方法是什么?
double retire62 = [benefit62.text doubleValue] * [yearlyReturn.text doubleValue] *12* [lblAgeExpectancy.text doubleValue];
double retire66 = [benefit66.text doubleValue] * [yearlyReturn.text doubleValue] *12* [lblAgeExpectancy.text doubleValue];
double retire70 = [benefit70.text doubleValue] * [yearlyReturn.text doubleValue] *12* [lblAgeExpectancy.text doubleValue];
Run Code Online (Sandbox Code Playgroud)
我只是不熟悉现值/
我有这两个javascript函数可以更改背景并显示和隐藏字段,但是每个按钮只能运行一次
function showabout(){
hidecontact = document.getElementById("contactus");
hidecontact.style.display = "none";
hide.style.backgroundImage = "url(aboutus.jpg)";
showabout = document.getElementById("aboutus");
showabout.style.display = "inline";
showabout.style.cssFloat = "left";
secbuttons.style.paddingLeft = "670px";
}
function showcontact(){
hideabout = document.getElementById("aboutus");
hideabout.style.display = "none";
hide.style.backgroundImage = "url(contact.jpg)";
showcontact = document.getElementById("contactus");
showcontact.style.display = "inline";
showcontact.style.cssFloat = "left";
secbuttons.style.paddingLeft = "670px";
}
<font color="#33FF66"><h2 style="cursor:pointer" onmouseover = "showabout()"> </h2></font>
<font color="#33FF66"><h2 style="cursor:pointer" onclick="showcontact()"> </h2></font><br />
<font color="#33FF66"><h2 style="cursor:pointer" onmouseover = "showcontact()"> </h2></font>
Run Code Online (Sandbox Code Playgroud)
三个H2是导致错误的线.它说"未捕获类型错误,对象不是函数".