小编Tec*_*Zen的帖子

触摸空格键时如何防止键盘从数字更改为字母?

UITextFields在桌子上输入值.其中一些字段仅接受数字.我UIKeyboardTypeNumbersAndPunctuation用于keyboardType,并shouldChangeCharactersInRange过滤字符.

此外,所有更正都被禁用:

textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
textField.autocorrectionType =  UITextAutocorrectionTypeNo;
textField.autocapitalizationType =  UITextAutocapitalizationTypeNone;
Run Code Online (Sandbox Code Playgroud)

在仅数字字段上,触摸空格键时,键盘将更改为字母.我知道这是默认行为.我想忽略空格键,不希望键盘类型改变.

有没有办法改变这种默认行为?

PS:其他数字键盘类型不是一个选项.我需要标点符号!

谢谢

iphone uitextfield iphone-sdk-3.0

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

问题解锁受密码保护的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
查看次数

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
查看次数

添加在文本字段中作为字符串输入的两个数字

我有两个文本字段,其中数字被输入为字符串.我需要将字符串转换为数字,将它们一起添加,然后在第三个文本字段中显示结果.

我对iPhone编程完全不熟悉..所以请不要对我很难:P

好的,这是问题所在

AdditionViewController.h

#import <UIKit/UIKit.h>

@interface AdditionViewController : UIViewController 
{
    IBOutlet UITextField *Number1;
    IBOutlet UITextField *Number2;
    IBOutlet UITextField *SumAnswer;
}

@property (retain, nonatomic) UITextField *Number1;
@property (retain, nonatomic) UITextField *Number2;
@property (retain, nonatomic) UITextField *SumAnswer;
-(IBAction)buttonPressed1:(id)sender;

@end
Run Code Online (Sandbox Code Playgroud)

AdditionViewController.m

#import "AdditionViewController.h"

    @implementation AdditionViewController
    @synthesize Number1;
    @synthesize Number2;
    @synthesize SumAnswer;


    -(IBAction)buttonPressed1:(id)sender
    {
        SumAnswer.text = Number1.text + Number2.text; 
           // I want the above line to be edited so that I can get the addition
             of both the numbers in the 3rd Text …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c

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

将NSManagedObject的实例添加到NSManagedObjectContext ok,更新同一实例失败

我在我的iPhone应用程序中使用核心数据.我创建了一个简单的类Friend,它派生自NSManagedObject并使用以下属性:

@property (nonatomic, retain) NSString *name;
Run Code Online (Sandbox Code Playgroud)

我能够在我的上下文中添加和删除此类的实例,并且我的更改也是持久的.
现在我想更新/修改一个Friend -instance并让它再次持久化.

但这似乎不起作用.

这是一段显示我的问题的代码:

//  NSManagedObjectContext *context  = < my managed context> 
//   NSFetchedResultsController *nsfrc= < my fetched result controller>

NSEntityDescription *entity = [nsfrc entity];
NSManagedObject *newManagedObject = [NSEntityDescription 
       insertNewObjectForEntityForName:[entity name]  inManagedObjectContext:context];

Friend *f = (Friend *) newManagedObject;
f.name = @"name1";
//1.  --- here context.hasChanges == 1 ---   ok

NSError *error = nil;
if (![context save:&error]) { ... }
//2.  --- here context.hasChanges == 0 --- …
Run Code Online (Sandbox Code Playgroud)

iphone core-data nsmanagedobject nsmanagedobjectcontext

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

使用类别和核心数据进行自定义排序 - 框架是否支持?

我正在为iPhone iOS 4.0开发,我有一个使用Core Data存储的生日对象列表(日期+名称).我想使用NSFetchedResultsController来检索按每个生日对象的下一个生日日期排序的列表.为此,我需要为排序描述符定义自己的逻辑.

我试过用:

[NSSortDescriptor sortDescriptorWithKey:@"birthdayDate" 
                              ascending:YES 
                               selector:@selector(compareNextBirthday:)];
Run Code Online (Sandbox Code Playgroud)

compareNextBirthday:我在NSDate类上创建的类别中定义的位置.

但是当我尝试获取数据时,我收到以下错误:"不支持的NSSortDescriptor选择器:compareNextBirthday:"

我花了好几个小时试图解决这个问题而没有运气...... Core Data是否支持这种自定义排序?我真的需要进行内存排序吗?

sorting core-data objective-c nssortdescriptor

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

核心数据应用程序是在iphone设备中崩溃

您好我正在设备中测试我的核心数据应用程序,但它在iphone中崩溃并且在模拟器中工作正常.这是我的代码..

- (NSManagedObjectContext *)managedObjectContext {

    if (managedObjectContext != nil) {
        return managedObjectContext;

    }
    NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
    if (coordinator != nil) {
        managedObjectContext = [[NSManagedObjectContext alloc] init];
        [managedObjectContext setPersistentStoreCoordinator:coordinator];
    }
    return managedObjectContext;
}



- (NSManagedObjectModel *)managedObjectModel {

    if (managedObjectModel != nil) {
        return managedObjectModel;
    }
    NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"TouristGuide" withExtension:@"momd"];
    managedObjectModel= [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];    
    NSLog(@"%@", modelURL);
    return managedObjectModel;
}


- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {


    if (persistentStoreCoordinator != nil) {
        return persistentStoreCoordinator;
    }

    NSString *storePath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent:@"TouristGuide.sqlite"]; …
Run Code Online (Sandbox Code Playgroud)

iphone xcode core-data

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

UIImageWriteToSavedPhotosAlbum工作......有时候

UIImageWriteToSavedPhotosAlbum有时只能工作.有时它有效,有时它不起作用,完全相同的功能.

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
NSLog(@"Saving image to camera roll...");
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
NSLog(@"Done!"); }
Run Code Online (Sandbox Code Playgroud)

我正在使用UIImagePicker控制器来获取然后调用该函数的图像.

有时它会将其保存到相机胶卷上,有时则根本不会.

任何人有任何想法?

提前致谢.

编辑:

UIImageWriteToSavedPhotosAlbum的完成方法有时返回错误:

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

cocoa-touch uiimagepickercontroller iphone-sdk-3.1

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

iPhone NSDateComponent错误日期1.1.2011?

我用'DateFromComponents'设置了一个日期,当我把它读出来......它的错误.我必须把DAY设置为第二个或之后的任何东西,所以我得到正确的年份?!?我设置2011年,当我读它我得到2010年!


 day = 1;
 month = 1;
 year = 2011;
 NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
 NSDateComponents *components = [[NSDateComponents alloc] init];
 [components setDay:day];
 [components setMonth:month];
 [components setYear:year];
 NSDate *date = [gregorian dateFromComponents:components]; 
 [gregorian release];


 NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; 
 [dateFormatter setDateFormat:@"DD MMMM YYYY"];
 NSLog (@"hmm: %@",[dateFormatter stringFromDate:actDate]);
Run Code Online (Sandbox Code Playgroud)

-------我来了1 January 2010 /// 2010 not 2011!?!?

如何解决这个问题.

克里斯

iphone nsdatecomponents

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

如何在谓词中使用"IN"运算符

如何编写NSPredicate来获取与数组中的值匹配的行?例如:

[NSPredicate predicateWithFormat:@"UserName IN %@",UserIDArray];
Run Code Online (Sandbox Code Playgroud)

如果UserIDArray包含用户ID,如何获取与此数组中的值匹配的用户名?

iphone core-data nspredicate nsfetchrequest ipad

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