小编Llo*_*rth的帖子

如何从照片库加载照片并将其存储到应用程序项目中?

我正在开发一个与我在这里找到的示例代码几乎相同的应用程序.但我想做的方法与示例代码不同.
链接:PhotoLocations

第一个屏幕将有一个ImageView和2个按钮(选择照片,确认).当点击"选择照片"按钮时,它将导航到另一个屏幕,该屏幕从我的iPad照片库中检索照片.选择照片后,它将关闭当前屏幕并返回到在ImageView上显示所选照片的​​第一个屏幕.

点击"确认"按钮后,照片将存储到我的应用程序项目中(例如/resources/images/photo.jpg).

我可以知道我该怎么办?

iphone xcode objective-c ipad ios

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

显示NSDocumentDirectory中的照片

我正在iPad上开发这个应用程序.

这些"浏览"按钮代码允许用户从iPad的图库中查看照片.

- (IBAction) BrowsePhoto:(id)sender
{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
[popover setPopoverContentSize:CGSizeMake(320,320)];
[popover presentPopoverFromRect:CGRectMake(200,200,-100,-100) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
self.popoverController = popover;
[imagePickerController  release];
}
Run Code Online (Sandbox Code Playgroud)

选择照片后,将使用NSDocumentDirectory将其存储到应用程序中.

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)selectedImage editingInfo:(NSDictionary *)editingInfo 
{
[self.popoverController dismissPopoverAnimated:YES];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *savedImagePath = [documentsDir stringByAppendingPathComponent:@"SavedImage.png"];
UIImage *image = imageView.image;
NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:savedImagePath atomically:NO];
}
Run Code Online (Sandbox Code Playgroud)

现在我必须在第一个屏幕上包含一个"显示"按钮.点击按钮时,它将显示一个新视图(模态视图控制器),并从NSDocumentDirectory显示缩略图/ tableview中的所有照片.

选择照片后,它将从NSDocumentDirectory中删除.

我怎样才能做到这一点?

xcode objective-c ipad ios nsdocumentdirectory

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

如何创建下载链接到Excel文件?

我有一个Excel电子表格(.xls),我希望用户能够从我的网页下载它.可能是页面上的"下载"按钮,当用户点击它时,将下载该文件.

我可以知道如何做到这一点?代码片段和参考将不胜感激.

html excel download

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

的Joomla! - 如何为用户注册添加额外信息?

我正在为我的网站运行Joomla 2.5.1.

对于用户注册,只有名称,用户名,密码,确认密码,电子邮件地址和确认电子邮件地址.

我可以转到'用户配置文件'并启用地址,国家等字段.
但是,我想添加其他信息,如公司名称等.

我可以知道如何做到这一点?

joomla registration

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

iPhone/iPad:无法将文件夹从NSBundle复制到NSDocumentDirectory

我想在我的NSBundle中复制一个包含大量图像的文件夹.
我尝试使用这些代码.

    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSError *error;
    NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory,
                                                         NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *documentDBFolderPath = [documentsDirectory stringByAppendingPathComponent:@"Images"];

    NSString *resourceDBFolderPath = [[[NSBundle mainBundle] resourcePath]
                                          stringByAppendingPathComponent:@"Images"];
        [fileManager copyItemAtPath:resourceDBFolderPath toPath:documentDBFolderPath error:&error];
Run Code Online (Sandbox Code Playgroud)

让我们说在名为Test.png的文件夹中有一个图像,我想在我的按钮上显示图像,它不起作用!
但是,如果我只将NSBundle中的单个图像复制到NSDocumentDirectory,它就可以了!

例:

更改

stringByAppendingPathComponent:@"Images"  
Run Code Online (Sandbox Code Playgroud)

stringByAppendingPathComponent:@"Test.png"
Run Code Online (Sandbox Code Playgroud)

所以问题在于将文件夹复制到NSDocumentDirectory!
我的代码是否错误?
或者是不可能复制文件夹?(这意味着我必须单独复制文件)

file-io objective-c nsfilemanager nsbundle ios

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

将多个文件复制到Documents目录

我想在应用程序启动时将多个文件从我的NSBundle复制到Documents目录.

这是复制文件的代码:

- (NSString *) getPath 
{
  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
  NSString *documentsDir = [paths objectAtIndex:0];
  return [documentsDir stringByAppendingString:@"Photo.png"];
}

- (void) copyFile 
{
  NSFileManager *fileManager = [NSFileManager defaultManager];
  NSError *error;
  NSString *Path = [self getPath];
  BOOL success = [fileManager fileExistsAtPath:Path];

  if(!success) {

    NSString *defaultPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Photo.png"];
    success = [fileManager copyItemAtPath:defaultPath toPath:Path error:&error];

    if (!success)
        NSAssert1(0, @"Failed to create writable file with message '%@'.", [error localizedDescription]);
  }
}
Run Code Online (Sandbox Code Playgroud)

copyFile方法将在'applicationDidFinishLaunchingWithOptions'方法中调用.但是此方法仅允许将一个文件复制到Documents目录.如果我想从我的NSBundle复制50个文件,这是否意味着我必须指定50个路径?有没有更短的方法,例如只用几行代码获取NSBundle中的所有文件?

iphone cocoa-touch objective-c ipad ios

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