IOS/ Objective-c: issue on MKMapView - objective-c

I'm new at objective-c/IOS and i'm following this tutorial about implementing user's current location on a map. Followed the instructions, but when I press the button to see my current location, nothing happens. Can anybody give me a hint? I'm using the latest version of Xcode and i'm not sure if the one in the tutorial is the same...The code:
ViewController.m:
#import "ViewController.h"
#import "Pin.h"
#interface ViewController ()
#end
#implementation ViewController;
#synthesize mapview;
- (void)viewDidLoad {
[super viewDidLoad];
MKCoordinateRegion region={{0.0,0.0},{0.0,0.0}};
region.center.latitude=38.711995;
region.center.longitude=-9.144932;
region.span.longitudeDelta=0.01f;
region.span.latitudeDelta=0.01f;
[mapview setRegion:region animated:YES];
Pin*vega =[[Pin alloc] init];
vega.title=#"Capela";
vega.subtitle=#"Bar";
vega.coordinate= region.center;
[mapview addAnnotation:vega];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)SetMap:(id)sender{
switch (((UISegmentedControl *) sender).selectedSegmentIndex) {
case 0:
mapview.mapType=MKMapTypeStandard;
break;
case 1:
mapview.mapType=MKMapTypeSatellite;
break;
case 2:
mapview.mapType=MKMapTypeHybrid;
break;
default:
break;
}
}
-(IBAction)GetLocation:(id)sender{
mapview.showsUserLocation=YES;
}
(IBAction)Directions:(id)sender{
NSString * urlString=#"http://maps.apple.com/maps?daddr=38.711995, -9.144932";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
}
#end
VieController.h:
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#interface ViewController : UIViewController{
MKMapView * mapview;
}
#property(nonatomic,retain)IBOutlet MKMapView* mapview;
-(IBAction)SetMap:(id)sender;
-(IBAction)GetLocation:(id)sender;
-(IBAction)Directions:(id)sender;
#end
And in the Connections Inspector everything (buttons) is set up..

You have to check/get the location permission :
add it to your plist file
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
and add that code to your VC:
if ([self.locationManager respondsToSelector:#selector(requestWhenInUseAuthorization)])
{
[self.locationManager requestWhenInUseAuthorization];
}

Related

Watch Connectivity not working

I am trying to create an app where I can send information from an apple watch to my ios Parent App. I have written the code for it but when I run the WatchConnectivity App, the information does not transfer between the apple watch and the parent ios app. This may be a problem with my code or it may be because for some reason the watch does not start with the app. I have to go to the simulator and click on the app to get it started. Is this why my code is not working?
InterfaceController.m
#import "InterfaceController.h"
#import <WatchConnectivity/WatchConnectivity.h>
#interface InterfaceController() <WCSessionDelegate>
#property (strong, nonatomic) WCSession *session;
#end
#implementation InterfaceController
-(instancetype)init {
self = [super init];
if (self) {
if ([WCSession isSupported]) {
self.session = [WCSession defaultSession];
self.session.delegate = self;
[self.session activateSession];
}
}
return self;
}
- (IBAction)catPressed {
[self sendText:#"cat"];
}
- (IBAction)dogPressed {
[self sendText:#"dog"];
}
- (IBAction)pandaPressed {
[self sendText:#"panda"];
}
- (IBAction)bunnyPressed {
[self sendText:#"bunny"];
}
-(void)sendText:(NSString *)text {
NSDictionary *applicationDict = #{#"emoji":text};
[self.session updateApplicationContext:applicationDict error:nil];
}
ViewController.m
#import "ViewController.h"
#import <WatchConnectivity/WatchConnectivity.h>
#interface ViewController () <WCSessionDelegate>
#property (weak, nonatomic) IBOutlet UILabel *textLabel;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
if ([WCSession isSupported]) {
WCSession *session = [WCSession defaultSession];
session.delegate = self;
[session activateSession];
NSLog(#"HIIII");
}
}
- (void)session:(nonnull WCSession *)session didReceiveApplicationContext:(nonnull NSDictionary<NSString *,id> *)applicationContext {
NSString *text = [applicationContext objectForKey:#"text"];
dispatch_async(dispatch_get_main_queue(), ^{
[self.textLabel setText:[NSString stringWithFormat:#"Text: %#", text]];
});
}
It turns out that I needed to open the parent app on the iPhone first to start sharing information between the iPhone and Watch. Thanks to MSU_Bulldog for suggesting this idea.

How do I go about handling Cocoa Events in a fullscreen application

I have been trying to create an app for Cocoa without a nib/xib (No, I don't want to use a nib/xib. I want to be in full control programatically) and I can't seem to be able to catch the Events such as keystrokes and mouse clicks. Here is the code I have so far:
Main.m
#import <Cocoa/Cocoa.h>
#import "AppDelegate.h"
int main(int argc, char *argv[])
{
#autoreleasepool {
NSApplication *app = [NSApplication sharedApplication];
AppDelegate *appDelegate = [[AppDelegate alloc] init];
[app setDelegate:appDelegate];
[app activateIgnoringOtherApps:YES];
[app run];
}
return EXIT_SUCCESS;
}
AppDelegate.h/m
#import <Cocoa/Cocoa.h>
#interface AppDelegate : NSObject <NSApplicationDelegate>
{
NSWindow *window;
}
#end
#import "AppDelegate.h"
#import "GLView.h"
#implementation AppDelegate
- (id)init{
self = [super init];
if (!self) {
return nil;
}
NSRect bounds = [[NSScreen mainScreen] frame];
GLView *view = [[GLView alloc]initWithFrame:bounds];
window = [[NSWindow alloc] initWithContentRect:bounds
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO];
[window setReleasedWhenClosed:YES];
[window setAcceptsMouseMovedEvents:YES];
[window setContentView:view];
return self;
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[window makeKeyAndOrderFront:self];
}
#end
GLView.h/m
#import <Cocoa/Cocoa.h>
#interface GLView : NSView
#end
#import "GLView.h"
#implementation GLView
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
}
return self;
}
- (void)drawRect:(NSRect)dirtyRect
{
// Drawing code here.
}
- (BOOL)canBecomeKeyView
{
return YES;
}
- (BOOL)acceptsFirstResponder
{
return YES;
}
- (BOOL)becomeFirstResponder
{
return YES;
}
- (BOOL)resignFirstResponder
{
return YES;
}
- (void)keyDown:(NSEvent *)theEvent
{
NSString* const character = [theEvent charactersIgnoringModifiers];
unichar const code = [character characterAtIndex:0];
NSLog(#"Key Down: %hu", code);
switch (code)
{
case 27:
{
EXIT_SUCCESS;
break;
}
}
}
- (void)keyUp:(NSEvent *)theEvent
{
}
#end
Nothing I have tried for it has worked. I thought that by setting the view as the first responder I would be able to get the events. So far... Not working. Any ideas on how I can fix this? Remember, NO NIB.
Thanks,
Tyler
First, you need to make sure that your window can actually become key, by subclassing and returning YES from canBecomeKeyWindow, because windows without title bars cannot become key by default.
Next, your build target needs to be an application. I would guess that you're starting from the Command-Line Tool template in Xcode. This is fine, but you need to produce an application bundle in order for your app to recieve key events. Create a new target in your project that will build a Cocoa Application. It needs to have an Info.plist file (from which you'll want to delete the "Main nib file base class" entry) and have a "Copy Bundle Resources" Build Phase.
I can't quite figure out what all the other differences are in the build process, but starting from your code, I got the window to accept key events with these two steps.

Passing value from one class to another, using #property

I have been pulling my hair out all afternoon trying to figure out why the following code will not work. All I am trying to do is pass a string, from one class to another.
In my FirstDetailViewController.h file I declare the NSString
#property(nonatomic, retain) NSString *infoForArray;
And then in my Grinding01_DetailViewController.m I try to set a value for the string
#import "Grinding01_DetailViewController.h"
#import "FirstDetailViewController.h"
#implementation Grinding01_DetailViewController
...
NSString *didLoadMessage = #"Grinding01 Loaded";
FirstDetailViewController *temp = [[FirstDetailViewController alloc] initWithNibName:#"FirstDetailView" bundle:nil];
temp.infoForArray = didLoadMessage;
[self.navigationController pushViewController:temp animated:YES];
}
When I output the infoForArray from the FirstDetailViewController.h it is null.
Any help would be appreciated, I think there's a simple step that I am missing, but I just can't see it.
EDIT: Here is the code from the FirstDetailViewController
FirstDetailViewController.h
#import <UIKit/UIKit.h>
#import "Protocols.h"
#interface FirstDetailViewController : UIViewController <SubstitutableDetailViewController> {
//for the output
IBOutlet UITextView *outputView;
UIToolbar *navigationBar;
NSMutableArray *logMessages;
}
#property (nonatomic, retain) IBOutlet UIToolbar *navigationBar;
//for incoming messages
#property(nonatomic, retain) NSString *infoForArray;
#end
FirstDetailViewController.m
#import "FirstDetailViewController.h"
#implementation FirstDetailViewController
#synthesize navigationBar, infoForArray;
-(void)viewDidLoad{
[super viewDidLoad];
//The log cannot be changed
outputView.editable = NO;
}
#pragma mark -
#pragma mark View lifecycle
- (void)viewDidUnload {
[super viewDidUnload];
self.navigationBar = nil;
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:YES];
NSLog(#"message: %#", infoForArray);
outputView.text = infoForArray;
}
#pragma mark -
#pragma mark Managing the popover
- (void)showRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem {
// Add the popover button to the toolbar.
NSMutableArray *itemsArray = [navigationBar.items mutableCopy];
[itemsArray insertObject:barButtonItem atIndex:0];
[navigationBar setItems:itemsArray animated:NO];
[itemsArray release];
}
- (void)invalidateRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem {
// Remove the popover button from the toolbar.
NSMutableArray *itemsArray = [navigationBar.items mutableCopy];
[itemsArray removeObject:barButtonItem];
[navigationBar setItems:itemsArray animated:NO];
[itemsArray release];
}
#pragma mark -
#pragma mark Rotation support
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
#pragma mark -
#pragma mark Memory management
- (void)dealloc {
[navigationBar release];
[super dealloc];
}
#end
It sounds like the trouble area is in in FirstDetailViewController. I would suggest posting the code for that so we can see what's going on.
my guess is you are checking for infoForArray somewhere in the instantiation process of FirstDetailViewController, which occurs before you set temp.infoForArray = didLoadMessage.
Just for reference, if you check for infoForArray in viewDidLoad that will be too early. viewDidLoad is triggered when the view is put into memory. What you want is viewDidAppear, which you may have to add yourself

Orientation Problem with more Views and Controller (iPad)

Im writing an App for iPad using Orientation.
The App-Delegate.h has a window, an UIViewController, an UINavigationController and an UITabbarController:
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet LoginRVC *loginRVC;
#property (nonatomic, retain) IBOutlet ChooseCameraRVC *chooseCameraRVC;
#property (nonatomic, retain) IBOutlet UITabBarController *hauptRVC;
Every Controller uses the "shouldAutorotateToInterfaceOrientation"-method to autorotate itself.
i change the views using:
[UIView beginAnimations:nil context:NULL];
and then
[loginRVC.view removeFromSuperview];
[_window addSubview:chooseCameraRVC.view];
and the other way around too, ofc.
So my problem is, when i am in the second view (chooseCameraRVC) and switch the orientation, then go back to my first view, its not rotated. It do autorotate but after the animation is completed.
I tried many things like calling "shouldAutorotateToInterfaceOrientation"-method of all views, not removing the views from window ... but no success til now.
Is this maybe a "feature" of the simulator? (i hope not).
Pls help me.
Sharky
Ok. I prepared my source code to be presented here.
Note: I didn't copy the methods which only has [super ...] within or are completely commented out.
At first the AppDelegate.h:
#import <UIKit/UIKit.h>
#import "ChooseCameraRVC.h"
#import "LoginRVC.h"
#interface NetCoWatchAppDelegate : NSObject <UIApplicationDelegate>
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet LoginRVC *loginRVC;
#property (nonatomic, retain) IBOutlet ChooseCameraRVC *chooseCameraRVC;
-(void)changeView:(id)sender:(BOOL)direction;
#end
AppDelegate.m:
#import "NetCoWatchAppDelegate.h"
#import "LoginRVC.h"
#import "ChooseCameraRVC.h"
#import "ChooseCameraVC.h"
#implementation NetCoWatchAppDelegate
#synthesize window = _window;
#synthesize loginRVC, chooseCameraRVC;
-(void)changeView:(id)sender:(BOOL)direction{
//configure animation
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2];
if(sender == loginRVC){ //sender is LoginView
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:_window cache:YES];
[loginRVC.view removeFromSuperview];
[_window addSubview:chooseCameraRVC.view];
}else if(sender == chooseCameraRVC){
[chooseCameraRVC.view removeFromSuperview];
if(!direction){ //FlipFromRight = YES, ...left = NO
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:_window cache:YES];
[_window addSubview:loginRVC.view];
}
}else if([sender class] == [ChooseCameraVC class]){
[chooseCameraRVC.view removeFromSuperview];
if(!direction){ //Camera gewählt //FlipFromRight = YES, ...left = NO
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:_window cache:YES];
[_window addSubview:loginRVC.view];
}
}else { //default solution
UIAlertView *av = [[UIAlertView alloc] initWithTitle:#"Bad Value" message:[[sender class] description] delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[av show];
[av release];
}
[UIView commitAnimations]; //start animation
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
// Add the navigation controller's view to the window and display.
[self.window makeKeyAndVisible];
return YES;
}
- (void)dealloc
{
[_window release];
[loginRVC release];
[chooseCameraRVC release];
[super dealloc];
}
#end
The LoginRVC.h:
#import <UIKit/UIKit.h>
#interface LoginRVC : UIViewController <UITextFieldDelegate>{
NSMutableArray *usernameArray;
NSMutableArray *passwordArray;
}
#property (nonatomic, retain) IBOutlet UITextField *usernameTF;
#property (nonatomic, retain) IBOutlet UITextField *passwordTF;
#property (nonatomic, retain) IBOutlet UIButton *loginBn;
#property (nonatomic, retain) IBOutlet UISwitch *saveUsernameSwitch;
-(IBAction)tryLogin:(id)sender;
-(IBAction)closeKeyboard:(id)sender;
#end
The LoginRVC.m:
#import "LoginRVC.h"
#import "NetCoWatchAppDelegate.h"
#implementation LoginRVC
#synthesize usernameTF, passwordTF, loginBn, saveUsernameSwitch;
-(IBAction)tryLogin:(id)sender{
//login successful if the textfields are euqal with an existing account
#warning Access the data base and search for the account.
bool accountFound = NO;
for (int i=0; i<usernameArray.count; i++) {
if([[usernameArray objectAtIndex:i] isEqualToString:usernameTF.text]
&& [[passwordArray objectAtIndex:i] isEqualToString:passwordTF.text]){
accountFound = YES;
break;
}
}
if(accountFound)
{ //login successful - now change the values and then the view
if(![saveUsernameSwitch isOn])
usernameTF.text = #"";
passwordTF.text = #"";
NetCoWatchAppDelegate *main = (NetCoWatchAppDelegate*)[[UIApplication sharedApplication] delegate];
[main changeView:self:YES];
}else{ //login failt - show a popup window for the user
UIAlertView *av = [[UIAlertView alloc] initWithTitle:#"Login fehlgeschlagen" message:#"Username oder Passwort falsch!" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[av show];
[av release];
}
}
-(IBAction)closeKeyboard:(id)sender{
if([passwordTF isFirstResponder])
[passwordTF resignFirstResponder];
else
[usernameTF resignFirstResponder];
}
// this helps dismiss the keyboard then the "done" button is clicked
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
if(textField == usernameTF){ //move to password textfield
[textField resignFirstResponder];
[passwordTF becomeFirstResponder];
}else if(textField == passwordTF){ //textField == passwordTF -> try to login
[textField resignFirstResponder];
[self tryLogin:self];
}
return YES;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.textFieldRounded.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
#warning Define right keyboard type.
usernameArray = [[NSMutableArray alloc] initWithObjects:#"dkoehn", #"bmazanek", #"sbehne", #"mballhausen", #"efiedler", #"bbraasch", #"azuber", #"tstolt", nil];
passwordArray = [[NSMutableArray alloc] initWithObjects:#"test1",#"test2",#"test3",#"test4",#"test5",#"test6",#"test7",#"test8", nil];
// usernameTF.keyboardType = UIKeyboardTypeEmailAddress;
[usernameTF becomeFirstResponder]; //get first focus when the app stars
//set return key on the keyboard and the delegate for an action
usernameTF.returnKeyType = UIReturnKeyNext; // type of the return key
passwordTF.returnKeyType = UIReturnKeyGo;
//set delegate to connect with a method "-(BOOL)textFieldShouldReturn:(UITextField *)textField"
usernameTF.delegate = self;
passwordTF.delegate = self;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
#end
The ChooseCameraRVC.h:
#import <UIKit/UIKit.h>
#interface ChooseCameraRVC : UINavigationController <UINavigationControllerDelegate>
#property (nonatomic, retain) IBOutlet UIBarButtonItem *zurueckBN;
-(IBAction)exitToLoginView:(id)sender;
#end
The ChooseCameraRVC.m:
#import "ChooseCameraRVC.h"
#import "NetCoWatchAppDelegate.h"
#import "ChooseCameraCell.h"
#implementation ChooseCameraRVC
#synthesize zurueckBN;
-(IBAction)exitToLoginView:(id)sender{
#warning Eventually logout the User.
//change the view
[((NetCoWatchAppDelegate*)[[UIApplication sharedApplication] delegate]) changeView:self:NO];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
#end
ChooseCameraVC.h:
#import <UIKit/UIKit.h>
#interface ChooseCameraVC : UITableViewController <UITableViewDelegate>
#end
and the ChooseCameraVC.m:
#import "ChooseCameraVC.h"
#import "ChooseCameraCell.h"
#import "NetCoWatchAppDelegate.h"
#implementation ChooseCameraVC
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Customize the number of sections if grouped.
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
#warning Get count of cameras out of the data base.
return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
cell.textLabel.text = #"Camera";
return cell;
}
#end
I hope u can find the problem.
Greetings. $h#rky
now i found my mistake. as u can see i have the views as variables in the app delegate. so if the second view changes the orientation, the other ones didn't know a thing about it. if the view now changes the "new" one recognizes the orientation change AFTER the animation, so while the animation is running, the "new" view has the wrong orientation.
So if u want to switch a view, just create a new one because it gets initialized with the right orientation.
kind regards
$h#rky
For support all orientations your viewcontroller should implement shouldAutorotateToInterfaceOrientation like this:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
Every viewcontroller should implement this method for support required orientations.
Check also Supported interface orientations item in .plist file. Maybe you have wrong parameters.
Try this in your secondviewcontroller
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
UIViewController *controller = [self.navigationController.viewControllers objectAtIndex:0];
[controller shouldAutorotateToInterfaceOrientation:interfaceOrientation];
return YES;
}
Hope it works..!!:)

How to Change view(XIB) after imagePickerController:didFinishPickingMediaWithInfo?

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
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
In didFinishPickingMediaWithInfo you should call [self.tabBarController setSelectedIndex:1] to switch to the second tab.