如何在 imagePickerController:didFinishPickingMediaWithInfo 之后更改视图(XIB)?

发布于 2024-10-09 13:56:37 字数 3309 浏览 1 评论 0原文

我是 iPhone 和 Objective-C 开发的新手。

我想知道相机拍照后如何更改视图(XIB 文件)。

有人可以帮助我或分享一些代码吗?我一周以来一直在寻找这个:( 完成应用程序后,我准备分享我的项目和/或制作教程。

有关我的应用程序的信息:我想扫描条形码并将条形码保存在我的应用程序中。 为了扫描条形码,我使用 ZBarSDK。 我有一个 TabBarController,在第一个选项卡上,我可以打开相机。 扫描过程结束后,我想跳到第二个选项卡(另一个 XIB 文件)并显示结果。

感谢您的任何帮助。

这是我的第一个选项卡 (ScanCodeViewController) 的代码:

.h

#import < UIKit/UIKit.h >

@class OutPutCodeViewController;

@interface ScanCodeViewController : UIViewController <ZBarReaderDelegate> {
 IBOutlet UIImageView *img;
 OutPutCodeViewController *output;         
}


@property (nonatomic, retain) IBOutlet UIImageView *img;
@property (nonatomic, retain) OutPutCodeViewController *output;

- (IBAction) scanButton;

@end

.m

#import "ScanCodeViewController.h"


@implementation ScanCodeViewController

@synthesize img;
@synthesize output;


- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}


- (void)dealloc {
[img release];
[super dealloc];
}


- (IBAction) scanButton {
 NSLog(@"Scanbutton wurde geklickt!");

 ZBarReaderViewController *reader = [ZBarReaderViewController new];
 reader.readerDelegate = self;

 ZBarImageScanner *scanner = reader.scanner;

 [scanner setSymbology: ZBAR_I25 config: ZBAR_CFG_ENABLE to: 0];

 [self presentModalViewController:reader animated: YES];
 [reader release];
 }


- (void) imagePickerController: (UIImagePickerController*) reader
 didFinishPickingMediaWithInfo: (NSDictionary*) info
{
 NSLog(@"Entered imagePickerController");


 // ADD: get the decode results
 id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];
 ZBarSymbol *symbol = nil;
 for(symbol in results) {
 break;
 }

 img.image = [info objectForKey:UIImagePickerControllerOriginalImage];
 [reader dismissModalViewControllerAnimated: YES];


 //[self presentModalViewController:output animated:YES]; //by using this, app chrashes 

}


- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
 [picker dismissModalViewControllerAnimated: YES];

}


@end  

这里是第二个选项卡 (OutPutCodeViewController)

.h

#import <UIKit/UIKit.h>


@interface OutPutCodeViewController : UIViewController {
 IBOutlet UIImageView *resultImage;
 IBOutlet UITextField *resultText;
}

@property (nonatomic, retain) IBOutlet UIImageView *resultImage;
@property (nonatomic, retain) IBOutlet UITextField *resultText;


@end

.m

#import "OutPutCodeViewController.h"


@implementation OutPutCodeViewController

@synthesize resultImage;
@synthesize resultText;


- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}


- (void)dealloc {
 [resultImage release];
 [resultText release];

[super dealloc];
}


@end

I am new on iphone and objective-c development.

I want to know how i can change the view (XIB File) after the camera takes a picture.

Can anyone help me or share some code? I am searching for this since a week :(
After finishing the app, i am ready to share my project and/or make a tutorial.

Infos about my App: i want to scan barcodes and save the barcodes in my app.
For scanning barcodes iam using the ZBarSDK.
I hava a TabBarController, on the first Tab, i can open the camera.
After the scan process i want to jump to the second tab (another XIB File) and show the results.

Thanks for any help.

Here my code of the first tab (ScanCodeViewController):

.h

#import < UIKit/UIKit.h >

@class OutPutCodeViewController;

@interface ScanCodeViewController : UIViewController <ZBarReaderDelegate> {
 IBOutlet UIImageView *img;
 OutPutCodeViewController *output;         
}


@property (nonatomic, retain) IBOutlet UIImageView *img;
@property (nonatomic, retain) OutPutCodeViewController *output;

- (IBAction) scanButton;

@end

.m

#import "ScanCodeViewController.h"


@implementation ScanCodeViewController

@synthesize img;
@synthesize output;


- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}


- (void)dealloc {
[img release];
[super dealloc];
}


- (IBAction) scanButton {
 NSLog(@"Scanbutton wurde geklickt!");

 ZBarReaderViewController *reader = [ZBarReaderViewController new];
 reader.readerDelegate = self;

 ZBarImageScanner *scanner = reader.scanner;

 [scanner setSymbology: ZBAR_I25 config: ZBAR_CFG_ENABLE to: 0];

 [self presentModalViewController:reader animated: YES];
 [reader release];
 }


- (void) imagePickerController: (UIImagePickerController*) reader
 didFinishPickingMediaWithInfo: (NSDictionary*) info
{
 NSLog(@"Entered imagePickerController");


 // ADD: get the decode results
 id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];
 ZBarSymbol *symbol = nil;
 for(symbol in results) {
 break;
 }

 img.image = [info objectForKey:UIImagePickerControllerOriginalImage];
 [reader dismissModalViewControllerAnimated: YES];


 //[self presentModalViewController:output animated:YES]; //by using this, app chrashes 

}


- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
 [picker dismissModalViewControllerAnimated: YES];

}


@end  

And here the Secong Tab (OutPutCodeViewController)

.h

#import <UIKit/UIKit.h>


@interface OutPutCodeViewController : UIViewController {
 IBOutlet UIImageView *resultImage;
 IBOutlet UITextField *resultText;
}

@property (nonatomic, retain) IBOutlet UIImageView *resultImage;
@property (nonatomic, retain) IBOutlet UITextField *resultText;


@end

.m

#import "OutPutCodeViewController.h"


@implementation OutPutCodeViewController

@synthesize resultImage;
@synthesize resultText;


- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}


- (void)dealloc {
 [resultImage release];
 [resultText release];

[super dealloc];
}


@end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

呆° 2024-10-16 13:56:37

知道了!

无法设置更多动画:是。
这是示例和正确的代码。

我希望它对其他人有帮助。

- (void) imagePickerController: (UIImagePickerController*) reader
 didFinishPickingMediaWithInfo: (NSDictionary*) info
{

    // ADD: get the decode results
    id<NSFastEnumeration> results =
    [info objectForKey: ZBarReaderControllerResults];
    ZBarSymbol *symbol = nil;
    for(symbol in results)
        break;

[reader dismissModalViewControllerAnimated: NO];

    TableDetailViewController *tc = [[TableDetailViewController alloc]         initWithNibName:@"TableDetailViewController" bundle:nil];
    tc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:tc animated:YES];
    [tc release];   

}

刷子51

Got it!

It is not possible to set more animate:YES.
Here is the sample and right code.

I hope it helps others.

- (void) imagePickerController: (UIImagePickerController*) reader
 didFinishPickingMediaWithInfo: (NSDictionary*) info
{

    // ADD: get the decode results
    id<NSFastEnumeration> results =
    [info objectForKey: ZBarReaderControllerResults];
    ZBarSymbol *symbol = nil;
    for(symbol in results)
        break;

[reader dismissModalViewControllerAnimated: NO];

    TableDetailViewController *tc = [[TableDetailViewController alloc]         initWithNibName:@"TableDetailViewController" bundle:nil];
    tc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:tc animated:YES];
    [tc release];   

}

brush51

赏烟花じ飞满天 2024-10-16 13:56:37

didFinishPickingMediaWithInfo 中,您应该调用 [self.tabBarController setSelectedIndex:1] 切换到第二个选项卡。

In didFinishPickingMediaWithInfo you should call [self.tabBarController setSelectedIndex:1] to switch to the second tab.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文