小编Jac*_*ack的帖子

iPhone(iOS):将文件从主包复制到文档文件夹错误

我试图在首次启动时将我的应用程序包中的一些文件复制到文档目录.我有第一次启动的检查,但为了清楚起见,它们未包含在代码段中.问题是我正在复制到文档目录(已经存在),在文档中,它说明:

在操作之前,dstPath不得存在.

对我来说直接复制到文档根目录的最佳方法是什么?我想这样做的原因是允许iTunes文件共享支持.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
  NSString *sourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Populator"];

  NSLog(@"\nSource Path: %@\nDocuments Path: %@", sourcePath, documentsDirectory);

  NSError *error = nil;

  if([[NSFileManager defaultManager] copyItemAtPath:sourcePath toPath:documentsDirectory error:&error]){
    NSLog(@"Default file successfully copied over.");
  } else {
    NSLog(@"Error description-%@ \n", [error localizedDescription]);
    NSLog(@"Error reason-%@", [error localizedFailureReason]);
  }
  ...
  return YES;
}
Run Code Online (Sandbox Code Playgroud)

谢谢

iphone nsfilemanager

8
推荐指数
2
解决办法
2万
查看次数

获取文档目录中的目录数组

我试图返回应用程序的Documents目录中的目录列表.我能够获得一个包含给定扩展名的所有文件的数组(例如.txt文件或.png文件),并且能够返回所有内容(包括目录).当我想只返回目录时出现问题.有一个简单的方法吗?

这是我返回所有.txt文件的代码:

- (ViewController *) init {
    if (self = [super init]) self.title = @"Text Files";

    // get the list of .txt files
    directoryList = [[[[NSFileManager defaultManager] directoryContentsAtPath:DOCUMENTS_FOLDER] 
                      pathsMatchingExtensions:[NSArray arrayWithObjects:@".txt", nil]] retain];
    NSLog(@"%@", directoryList);

    return self;
}
Run Code Online (Sandbox Code Playgroud)

并为所有文件

- (ViewController *) init {
    if (self = [super init]) self.title = @"Text Files";

    // get the list of all files and directories
    directoryList = [[[NSFileManager defaultManager] directoryContentsAtPath:DOCUMENTS_FOLDER] retain];

    NSLog(@"%@", directoryList);

    return self;
}
Run Code Online (Sandbox Code Playgroud)

iphone nsfilemanager

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

CakePHP的用户管理,身份验证和acl插件?

我是CakePHP的新手,已经使用了一段时间的rails.我的问题是,有人可以为Cake推荐一个好的用户管理,身份验证和acl插件或组件吗?

我遇到过这个,但自2008年以来一直没有更新过.如果不是,有人可以为这种设置推荐一本好的书/教程网站吗?我非常高兴自己坐下来写这种东西,但宁可使用经过测试的社区插件.

干杯

php authentication acl cakephp

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

UIView背景颜色

我正在尝试使用UITableView创建一个网格视图(我的老问题已指向我这个方向),我正在设置各个项目的视图.创建了一个每行显示3个项目的自定义UITableViewCell后,我决定将这些项目放入一个名为ItemView的UIView子类中.

然后将此ItemView作为子视图添加到自定义UITableViewCell以显示网格.无论如何,我已经设法创建了视图,并且可以让它显示UILabel罚款,但是我无法将ItemView更改为透明,而不是其中的UIViews(标签,按钮,图像等).这是我的UIView代码:

#import <UIKit/UIKit.h>
@interface ItemView : UIView {
}
@end

#import "ItemView.h"
@implementation ItemView

- (id)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {
    }
    return self;
}

- (void)drawRect:(CGRect)rect {
  [self setBackgroundColor:[UIColor lightGrayColor]];
}

- (void)dealloc {
  [super dealloc];
}
@end
Run Code Online (Sandbox Code Playgroud)

我应该在哪里设置背景颜色才能正常工作?

干杯

iphone uiview

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

如何在LaTeX中安装包

我是LaTeX的新手,但是几年来我一直在使用我自己的文档模板进行基本排版.我想要做的是从PSTricks 添加pst- gantt包.

我之前从未安装过新的软件包,但希望它可用于我的所有项目.为了完整起见,我正在运行OSX10.6并使用TeXShop编辑文本,但是我正在慢慢切换到TextEdit.

无论如何,我用google搜索,结果都说使用.dtx和.ins文件(我找不到).如果有人可以给我一些关于我需要安装什么的指示(我首先需要PSTricks吗?)以及如何去做,这将是很棒的.

谢谢

latex install package

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

文件目录的CFURLRef

我正在创建一个需要访问文档目录的应用程序.我目前正在使用以下命令pdfName从主包中返回文件的URL .获取文档目录有类似的方法吗?

CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), (CFStringRef)pdfName, NULL, NULL);
Run Code Online (Sandbox Code Playgroud)

编辑:这是我的完整代码,但它不起作用 - 任何想法?

    NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *myFilePath = [documentsDirectory stringByAppendingPathComponent:pdfName];

    CFURLRef pdfURL = (CFURLRef)[NSURL fileURLWithPath:myFilePath];
    pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);
    CFRelease(pdfURL);
Run Code Online (Sandbox Code Playgroud)

iphone

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

Rails转换日期格式

我在我的应用程序中有一个表单输入,它接受DD/MM/YYYY格式的日期,例如02/05/2012是2012年5月2日.

我通过ActiveRecord将其转换为适合添加到数据库的格式的最佳方式是什么?

在添加到数据库之前,有没有简单的方法将02/05/2012转换为05/02/2012?

ruby-on-rails date

4
推荐指数
2
解决办法
8356
查看次数

NSString反斜杠转义

我正在开发一个向Web服务发送xml请求的iPhone OS应用程序.为了发送请求,xml被添加到NSString.这样做时,我在xml文件中遇到了引号"和反斜杠\的问题,这些问题需要转义.是否有需要转义的完整字符列表?

Also, is there an accepted way of doing this escaping (ie replacing \ with \\ and " with \") or is it a case of creating a method myself?

Thanks

xml iphone backslash nsstring

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

带有自定义标识符(不是id)的Rails URL

我正在创建一个用于管理单个项目的Rails应用程序.每个项目都有一个项目编号(零填充,4位数字,例如000202121002),我想在应用程序的网址中使用.如果我当前导航到/items/2我获取项目id = 2而不是项目item_number = 2.我的routes.rb文件只包含resources :items; 我怎样才能允许这个项目号码拉出项目?

ruby ruby-on-rails ruby-on-rails-3

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

这种红宝石(铁轨)方法可以整理吗?

我对ruby很新(并且正在使用Rails)并且想知道以下方法是否可以整理.在它当前的状态下它确实有效,但我觉得有一种更好的编写方式,并希望了解更多关于语法的知识.

def fullAddress
  full = self.address1 + "</br>"
  if self.address2.blank?
  else
    full = full + self.address2  + "</br>"
  end
  if self.address3.blank?
  else
    full = full + self.address3  + "</br>"
  end
  full = full + self.posttown + "</br>" + self.postcode
end
Run Code Online (Sandbox Code Playgroud)

每个'self'都有address1,posttown和postcode,但是address2和address3是可选的,只有当它们存在时才应该添加到fullAddress(即既不是nil也不是空白).

这个问题可能不适合SO,但我已经遇到过这种类型的辅助方法,并且我确信我可以以更好的方式实现它.

ruby ruby-on-rails

1
推荐指数
2
解决办法
150
查看次数

iPhone自定义委托问题

我为我的班级'HotRequest'设置了一个委托,但是在实现它时遇到了问题.我班的代码如下.有任何想法吗?谢谢

HotRequest.h

#import <Foundation/Foundation.h>

@protocol HotRequestDelegate;

@interface HotRequest : NSObject {
    NSString *requestString;
    id <HotRequestDelegate> delegate;
}

@property (nonatomic, retain) NSString *requestString;
@property (nonatomic, assign) id <HotRequestDelegate> delegate;

- (id)initWithRequestOptions:(NSDictionary*)dict;

@end

@protocol HotRequestDelegate <NSObject>
@required
- (void)requestComplete;
@end
Run Code Online (Sandbox Code Playgroud)

HotRequest.m

#import "HotRequest.h"

@implementation HotRequest

@synthesize requestString, delegate;

- (id)initWithRequestOptions:(NSDictionary*)dict {
    if ((self = [super init])) {
        for (NSString *key in [dict allKeys]) {
            requestString = [NSString stringWithFormat:@"%@&%@=%@", requestString, key, [dict objectForKey:key]];
        }
        NSLog(@"%@", requestString);
    }
    [delegate requestComplete];
    return self;
}

@end …
Run Code Online (Sandbox Code Playgroud)

iphone delegation ios

0
推荐指数
1
解决办法
2543
查看次数

如何写这个没有点符号

有人可以帮我写下面的内容,不使用点符号:

self.bounds.size.width
Run Code Online (Sandbox Code Playgroud)

我试过了[[[self bounds] size] width],但这会导致错误.有任何想法吗?

iphone objective-c ios

0
推荐指数
2
解决办法
333
查看次数