小编Abi*_*ern的帖子

如何以编程方式设置NSView层

这样做的正确方法是什么?这是我正在尝试的.但是dotLayer上从不调用display:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    DotLayer *dotLayer = [[DotLayer alloc]init ];
    dotLayer.frame= CGRectMake(10, 10, 100, 100);
    dotLayer.nDots = 4;
    NSView *contentView = window.contentView;
    CALayer *layer = [[CALayer alloc]init];
    layer.frame = CGRectMake(0,0,200,200);
    contentView.layer = layer;
    [layer addSublayer:dotLayer];
    [dotLayer setNeedsDisplay];
}
Run Code Online (Sandbox Code Playgroud)

DotLayer是CALayer的子类.

cocoa calayer

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

如何在应用程序中使用iPhone铃声

我想在我的应用程序中使用iPhone的铃声.这可能吗?请帮助我坚持这一点,

谢谢

iphone

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

将NSString转换为特定于语言环境的NSNumber

我正在使用KeyboardType = UIKeyboardTypeDecimalPad和在某些手机上你看到左下角的","而不是".".这取决于手机的语言设置!随着"." 版本一切正常,当我使用[NSNumber numberWithFloat:[textField.text floatValue]]但是使用","版本时它表示2.0为2.5.有人知道解决方法吗?

iphone nsnumber nsstring ios

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

我如何使用 NSTask 获得类似于 Tail -f 的东西

我需要实时将最后添加的行读取到日志文件中,并捕获添加的那一行。

类似于 Tail -f 的东西。

所以我的第一次尝试是使用 NSTask 使用 Tail -f。

使用以下代码我看不到任何输出:

    NSTask *server = [[NSTask alloc] init];
    [server setLaunchPath:@"/usr/bin/tail"];
    [server setArguments:[NSArray arrayWithObjects:@"-f", @"/path/to/my/LogFile.txt",nil]];

    NSPipe *outputPipe = [NSPipe pipe];
    [server setStandardInput:[NSPipe pipe]];
    [server setStandardOutput:outputPipe];

    [server launch];
    [server waitUntilExit];
    [server release];

    NSData *outputData = [[outputPipe fileHandleForReading] readDataToEndOfFile];
    NSString *outputString = [[[NSString alloc] initWithData:outputData encoding:NSUTF8StringEncoding] autorelease];
    NSLog (@"Output \n%@", outputString);
Run Code Online (Sandbox Code Playgroud)

使用时我可以看到预期的输出:

[server setLaunchPath:@"/bin/ls"];
Run Code Online (Sandbox Code Playgroud)
  1. 如何捕获该尾部 NSTask 的输出?

  2. 这种方法有什么替代方法,我可以打开一个流到文件,每次添加一行时,将它输出到屏幕上?(基本日志功能)

objective-c tail nstask

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

执行某些系统事件,Mac OS X.

我想要

  • 关掉
  • 重新开始
  • 注销
  • 睡觉

我的系统通过我正在制作的应用程序,我似乎无法找到任何原生的Objective C方式来做它并且它真的很难.

任何人都可以指导我做最好的方法:

我试过了:

NSString *scriptAction = @"restart"; // @"restart"/@"shut down"/@"sleep"/@"log out"
NSString *scriptSource = [NSString stringWithFormat:@"tell application \"Finder\" to %@", scriptAction];
NSAppleScript *appleScript = [[[NSAppleScript alloc] initWithSource:scriptSource] autorelease];
NSDictionary *errDict = nil;
if (![appleScript executeAndReturnError:&errDict]) {
    //
}
Run Code Online (Sandbox Code Playgroud)

这根本没有运气,也尝试过:

NSAppleScript* theScript = [[NSAppleScript alloc] initWithSource:
                            @"Tell application \"Finder\" to restart"];
if (theScript != NULL)
{
    NSDictionary* errDict = NULL;
    // execution of the following line ends with EXC
    if (YES == [theScript compileAndReturnError: &errDict]) …
Run Code Online (Sandbox Code Playgroud)

macos shutdown objective-c logout

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

iOS上的C#下拉组合框相当于什么?

我正在使用Objective-C for iPhone编写应用程序.

在此应用程序中,用户在输入新记录时需要具有查找功能(例如状态,性别,电话类型等).在C#中我通常使用下拉组合或类似的东西来完成这项任务.Objective-C中的等价物是什么?有人可以给我看一个样例申请吗?

iphone objective-c

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

Xcode和SCM冲突错误

即使我是唯一一个从事这个项目的人,我也会收到以下错误.

> Error: 155015 (A conflict in the working copy obstructs the current operation) Description: Commit failed
Run Code Online (Sandbox Code Playgroud)

为什么会发生这种情况,因为我所做的就是每次都要在做一些严肃的编码之前提交项目.我已经提交了三次现在它不再允许,因为它抛出了这个错误.

svn version-control xcode conflict

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

如何清除Django模型中的一对一关系?

我在两个模型之间使用一对一的关系,我需要能够清除这种关系.但是,我找不到清除(clear(),remove()等的方法...)删除该关系,Django管理员不会执行该操作.有没有人有这个问题的经验?我想我可能必须跳过一对一的字段并在字段上使用一对多的unique = true set.

编辑:我应该提到.我确实在该字段上设置了null = True,但它没有任何区别.

django

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

NSDate为"下一小时的开始"

我想倒计时到下一个小时.倒计时到特定时间非常容易,例如:

NSDate *midnight = [NSDate dateWithNaturalLanguageString:@"midnight tomorrow"]; 
Run Code Online (Sandbox Code Playgroud)

如何为"每小时的开始"定义NSDate?

谢谢!

编辑:这是我目前的.无法将解决方案集成到我的代码中.任何帮助将不胜感激.:)

-(void)updateLabel {
NSDate *now = [NSDate date];

NSDate *midnight = [NSDate dateWithNaturalLanguageString:@"midnight tomorrow"]; 

//num of seconds between mid and now
NSTimeInterval timeInt = [midnight timeIntervalSinceDate:now];
int hour = (int) timeInt/3600;
int min = ((int) timeInt % 3600) / 60;
int sec = (int) timeInt % 60;
countdownLabel.text = [NSString stringWithFormat:@"%02d:%02d:%02d", hour, min,sec];
}  
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch nsdate

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

在使用之前,如何确保对象已完成初始化?

在一个方法中编写一些Objective-C,我调用+alloc,然后-init设置一个对象.

object = [[MyClass alloc] init];
[object useFor:whatever];
Run Code Online (Sandbox Code Playgroud)

接下来的几行代码使用新创建的对象.如果前面提到的-init时间太长,我确定程序在开始使用新对象之前不会"等待",是吗?如果没有,是否有快速确保-init完成的方法?

我有时会看到编写程序的程序员

if(object = [[MyClass alloc] init]) {
    [object useFor:whatever];
}
Run Code Online (Sandbox Code Playgroud)

这是我应该去做的吗?

oop initialization objective-c

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