小编Tec*_*Zen的帖子

Cocoa setAnimationDidStopSelector

目前我有这个代码工作正常

[UIView setAnimationDidStopSelector:@selector(animationDone:finished:context:)];

- (void)animationDone:(NSString *)animationID finished:(BOOL)finished context:(void *)context {
// do stuff here
}
Run Code Online (Sandbox Code Playgroud)

记录animationID的值会给我一个null.

如何将值传递给@selector?

我试过了

[UIView setAnimationDidStopSelector:@selector(animationDone:@"animation1"finished:context:)];
Run Code Online (Sandbox Code Playgroud)

这给了我一个错误.

谢谢,Tee

iphone objective-c

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

理智检查MKCoordinateRegion

有没有办法快速测试是否MKCoordinateRegion好?我已将纬度换成经度并导致应用程序崩溃.我希望能够看到setRegion在实际执行之前是否可以执行.会MKCoordinateRegionMake测试我给它的值吗?

谢谢.

iphone cocoa-touch mkmapview

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

iPhone核心数据:可转换属性是否必须转换为仅数据?

我一直在核心数据中使用可变形属性来将图像和颜色等复杂对象转换为原始数据.我拿了这个 ......

可转换属性背后的想法是您将属性作为非标准类型访问,但在幕后,Core Data使用NSValueTransformer的实例将属性转换为NSData实例和从NSData实例转换属性.然后,Core Data将数据实例存储到持久性存储中.

...表示您只能将数据转换为数据,而不能转换为其他类型的属性(如字符串).

我突然意识到情况可能并非如此.文档可能只是谈论最常见的情况.IIRC,在Cocoa绑定中,转换可以在很大程度上是任意的.例如,可以将NSURL转换为NSString进行显示,然后将其反转.

在我浪费时间进行实验并可能得到令人困惑的结果之前,我想知道是否有人确切知道转换是仅仅来自数据还是来自数据.

iphone cocoa core-data cocoa-bindings

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

wait_fences:收不到回复:10004003 - 什么?

得到这个奇怪的错误.

继承人的交易 - 在下面的方法我有一个警报视图上来,需要U/N和PW,然后atempt启动另一个方法.

方法

   -postTweet
Run Code Online (Sandbox Code Playgroud)

没有激活

我只是在控制台中收到此错误

 wait_fences: failed to receive reply: 10004003
Run Code Online (Sandbox Code Playgroud)

这真的很奇怪 - 我以前从未见过它

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (alertView == completeAlert ) {
        if (buttonIndex ==1) {
            passPromtAlert = [[UIAlertView alloc] initWithTitle:@"Enter Name" message:@"Please enter your Username and password - they will be saved\n" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Tweet", nil];
            [passPromtAlert addTextFieldWithValue:@"" label:@"Enter username"];
            [passPromtAlert addTextFieldWithValue:@"" label:@"Enter password"];

            textField = [passPromtAlert textFieldAtIndex:0];
            textField2 = [passPromtAlert textFieldAtIndex:1];
            textField.clearButtonMode = UITextFieldViewModeWhileEditing;
            textField.keyboardType = UIKeyboardTypeAlphabet;
            textField.keyboardAppearance = UIKeyboardAppearanceAlert;
            textField.autocapitalizationType  = UITextAutocapitalizationTypeWords; …
Run Code Online (Sandbox Code Playgroud)

uitextfield uialertview iphone-sdk-3.0

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

在ERB模板中转义行返回/结束行

我需要能够在ERB中格式化未打印的逻辑行,而不会影响模板的最终文本输出.在这一点上,我认为ERB不支持这种逃避.

这是我的第一个主要Ruby项目.我正在编写代码生成器.我的模板将包含大量的条件和枚举.为了使模板可读和可维护,我需要能够格式化逻辑代码和注释,而不会扭曲最终输出.

例如假设我想要这个输出:

Starting erbOutput
1
2
3
4
Ending erbOutput
Run Code Online (Sandbox Code Playgroud)

我天真地写了这样的模板:

require 'erb'
h=<<H
Starting erbOutput
<%# comment %>
<%5.times do |e|%>
<%=e.to_s  %>
<%end %>
<%# comment %>
Ending erbOutput
H
s=ERB.new(h).result
puts s
Run Code Online (Sandbox Code Playgroud)

......但这会产生

Starting erbOutput


0

1

2

3

4


Ending erbOutput
Run Code Online (Sandbox Code Playgroud)

直印:

"Starting erbOutput\n\n\n0\n\n1\n\n2\n\n3\n\n4\n\n\nEnding erbOutput\n"
Run Code Online (Sandbox Code Playgroud)

...清楚地表明逻辑和注释行的换行符包含在ERB输出中.

我可以通过将模板塞入这种笨拙的形式来产生所需的输出:

h=<<H
Starting erbOutput<%# comment %>
<%5.times do |e|%><%=e.to_s  %>
<%end %><%# comment %>Ending erbOutput
H
Run Code Online (Sandbox Code Playgroud)

...但我不认为我可以在没有更多可读格式的情况下调试和维护模板.我的一些条件和枚举深达三个级别,我评论很多.在一行或两行上填写所有内容会使模板完全无法读取.

有没有办法逃避或以其他方式抑制ERB中注释行的逻辑行返回?其他常用的Ruby模板模块是否能更好地处理这个问题?

如果它很重要,我在MacOS 10.6.7上使用MacRuby 0.10(实现Ruby 1.9.2).

ruby formatting erb macruby

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

问题解锁受密码保护的PDF文档

我需要帮助解锁加密的PDF文档.

我试过以下但没有成功.

CFURLRef pdfURL = CFURLCreateWithFileSystemPath (NULL, documentsDirectory,  kCFURLPOSIXPathStyle, 0); //1
pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);
BOOL encrypted = CGPDFDocumentIsEncrypted(pdf);
if (encrypted) {

// Try 1:

    const char *str = (char *)theTextField.text; 
    BOOL _unlock = CGPDFDocumentUnlockWithPassword(pdf,str);

//Try 2:

    NSString *str1 = @"password";
    BOOL _unlock1 = CGPDFDocumentUnlockWithPassword(pdf,str1); 
}
Run Code Online (Sandbox Code Playgroud)

我确保密码正确但解锁功能仍然返回False.

我忘记了什么?有什么不对的吗??

此致,Arun Thakkar.

pdf iphone

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

使用UITextView防止自动换行

使用Iphone sdk 3.1.2

我有一个UITextView控件,启用了垂直和水平滚动.我想要显示每行文本而不包装,以便用户可以水平滚动查看它.我的问题是,即使启用水平滚动,文本包裹在iPhone屏幕的宽度即320像素.

我该如何防止包裹?

谢谢

iphone uitextfield

5
推荐指数
2
解决办法
7420
查看次数

适用于iPhone的Soundtouch

有人能够 为iPhone工作http://www.surina.net/soundtouch/吗?

简单的Xcode演示会很有帮助.

我只想用一些音调操作来发挥作用.

克里斯

iphone audio core-audio

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

如何在不重复的情况下插入与另一个相关的核心数据记录

我有两个核心数据实体,ArticlesFavorite.Articles与To-Many有关系Favorite.首先,我Articles成功插入了所有对象.

现在,我正在尝试在"收藏夹"实体中插入ArticleID,但我不能.记录插入时为空关系,或者在"文章"实体中插入新记录.

我认为我应首先获取Articles实体中的相关记录,然后使用它插入Favorite但我不知道如何做到这一点.我目前的代码:

NSManagedObjectContext *context =[appDelegate managedObjectContext] ; 
favorite *Fav =[NSEntityDescription insertNewObjectForEntityForName:@"favorite" inManagedObjectContext:context];
Articles * Article = [NSEntityDescription insertNewObjectForEntityForName:@"Articles" inManagedObjectContext:context];

NSError *error;

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; 
NSEntityDescription *entity = [NSEntityDescription 
                               entityForName:@"Articles" inManagedObjectContext:context];  
[fetchRequest setEntity:entity]; 
NSPredicate *secondpredicate = [NSPredicate predicateWithFormat:@"qid = %@",appDelegate.GlobalQID ];
NSPredicate *thirdpredicate = [NSPredicate predicateWithFormat:@"LangID=%@",appDelegate.LangID]; 
NSPredicate *comboPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects: secondpredicate,thirdpredicate, nil]]; 
[fetchRequest setPredicate:comboPredicate];
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
for …
Run Code Online (Sandbox Code Playgroud)

core-data duplication objective-c one-to-many relationship

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

Ruby:如何处理失败或无效的初始化

什么是处理由于传递无效的初始化参数而导致对象无法初始化的情况的ruby最佳实践?

我意识到在红宝石中,鸭子打字意味着我们不应该过分关注变量/参数类型,而是关注它们的行为方式.但是,我在MacRuby中工作,它通过Cocoa Objective-C API进行桥接,一些Cocoa方法需要类型参数.

例如,我有一个调用Objective-C API的ruby类,并且必须将它传递给NSURL类的对象.它看起来像这样:

class Alpha
  attr_accessor :model
  def initialize(hopefully_a_NSURL)
    # bridged from Objective-C API
    @model=NSManagedObjectModel.alloc.initWithContentsOfURL(hopefully_a_NSURL)    
  end # initialize  
end 
Run Code Online (Sandbox Code Playgroud)

......我会这样称呼它:

#bridged from Objective-C API
u=NSURL.fileURLWithPath(p)
a=Alpha.new(u)
puts "a=#{a.model}" # => a=#<NSManagedObjectModel:0x2004970e0
Run Code Online (Sandbox Code Playgroud)

>

......效果很好.

但是,如果我要滑倒:

a=Alpha.new("Whoops, a string not a NSURL" )
Run Code Online (Sandbox Code Playgroud)

......它因为来自Objective-C API深处的错误而乱七八糟地爆炸.

当然,我可以进行测试,以防止到达桥接对象的错误参数:

class Alpha
  attr_accessor :model
  def initialize(hopefully_a_NSURL)
    if hopefully_a_NSURL.class==NSURL
      @model=NSManagedObjectModel.alloc.initWithContentsOfURL(hopefully_a_NSURL) 
    end   
  end # initialize  
end 


u=NSURL.fileURLWithPath(p)
a=Alpha.new("")
puts "a=#{a}" # => a=#<Alpha:0x200399160>
Run Code Online (Sandbox Code Playgroud)

...但我仍然得到了一个实时实例.我甚至尝试从初始化返回nil,但似乎ruby坚持总是返回一个实例.

我读到的所有内容都表明类型检查在ruby中非常不受欢迎,但在MacRuby的情况下我可能不得不例外.这可以很好地利用ruby中的异常,还是有更优雅的解决方案?我是红宝石的菜鸟,所以假设我从错误的角度来看待这个问题.

ruby exception-handling initialization macruby

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