我是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
这里是 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