我是iphone和Objective-c开发的新手。
我想知道如何在相机拍照后更改视图(XIB文件)。
任何人都可以帮助我或分享一些代码吗?我一周以来都在寻找这个:( 完成应用程序后,我准备好分享我的项目和/或制作教程。
关于我的应用程序的信息:我想扫描条形码并将条形码保存在我的应用程序中。 使用ZBarSDK扫描条形码。 我有一个TabBarController,在第一个Tab上,我可以打开相机。 在扫描过程之后,我想跳转到第二个选项卡(另一个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
答案 0 :(得分:3)
知道了!
无法设置更多动画:是。 这是示例和正确的代码。
我希望它可以帮助别人。
- (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
答案 1 :(得分:0)
在didFinishPickingMediaWithInfo
中,您应拨打[self.tabBarController setSelectedIndex:1]
切换到第二个标签。