Good evening,
I'm having problems with an app where a MapView is loaded when a User pushs the Bar Button on a ViewController. The MapViewController gets loaded and the Map shows correct annotations (not shown in source), but the startregion is wrong the first time the App is started and the MapView is opened. When I push the Back button once and reopen the MapView the startregion is fine. It just doesn't work for the first time.
the log gives me the correct values loaded from the plist:
47.572132 and 7.579397
Since I started coding objective-c two weeks ago, please keep your answers as simple as possible ;-)
h.File:
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
#import "DetailViewController.h"
#import "Annotation.h"
#interface MapViewController : UIViewController<CLLocationManagerDelegate> {
IBOutlet MKMapView *singlemapview;
}
#property (nonatomic, retain) NSArray *data;
#property int selectedBuilding;
#property (strong, nonatomic) CLLocationManager *location;
#property float longitude;
#property float latitude;
#end
m.File:
#import "MapViewController.h"
#interface MapViewController ()
#end
#implementation MapViewController
#synthesize data;
#synthesize selectedBuilding;
#synthesize location, latitude, longitude;
- (void)viewDidLoad
{
[super viewDidLoad];
NSDictionary *dataItem = [data objectAtIndex:selectedBuilding];
latitude = [[dataItem objectForKey:#"Latitude"] floatValue];
longitude = [[dataItem objectForKey:#"Longitude"] floatValue];
NSLog (#"%f",latitude);
NSLog (#"%f",longitude);
MKCoordinateRegion startregion = { {0.0, 0.0}, {0.0, 0.0} };
startregion.center.latitude = latitude;
startregion.center.longitude = longitude;
startregion.span.latitudeDelta = 0.005;
startregion.span.longitudeDelta = 0.005;
[singlemapview setMapType:MKMapTypeSatellite];
[singlemapview setZoomEnabled:YES];
[singlemapview setScrollEnabled:YES];
[singlemapview addAnnotation:singlebuilding];
[singlemapview setRegion:startregion];
}
My app had exactly the same behavior when calling setRegion method in viewDidLoad or viewWillAppear. but, calling it in viewDidAppear corrected the problem. hope this helps.
I could solve my problem now through using the -(void)viewWillAppear:(BOOL)animated function instead of using -(void)viewDidLoad
As i understand now:
ViewDidLoad is called once before a new view is opened (before the segue animation starts). But it is however still too late to draw the map correctly.
ViewDidAppear is called every time after a view did appear on the screen (after the segue animation is over).
ViewWillApper is called and calculated totally before a new view is opened (before segue animation). That's why it works properly when you have a map.
Related
I have found a tiny variant of the usual delegation pattern:
My protocol is defined in some Protocol.h, i.e,
#protocol ProtocolDelegate <NSObject>
//…
#end
//The variant, see below
typedef NSObject <ProtocolDelegate> Delegate;
Next, in my ViewController.h
#interface: UIViewController
#property (nonatomic, strong) Delegate*delegateOfviewController;
//…
#end
Then, in my ViewController.m
#implementation ViewController
#synthesize delegateOfviewController;
//…
#end
Finally, in my AppDelegate.m
//…
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//…
self.ViewController.delegateOfviewController = self;
//…
[self.window makeKeyAndVisible];
return YES;
}
And everything goes perfectly well. Is it really equivalent to the usual way " id delegate", or do you think that such a typedef should be avoided?
Thanks!
jgapc
The only difference should be whether or not you use a pointer symbol. I do not believe there is any difference, but why make a typedef when Objective-C gives you id?
I downloaded tesseract demo code of "rcarlsen-Pocket-OCR-9912da9" from https://github.com/rcarlsen/Pocket-OCR/downloads
Now i am facing problems with libraries used in it.Can anyone tell how can i solve this?or from where i can get it?
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
#import "ZoomableImage.h"
// conditionally import or forward declare to contain objective-c++ code to here.
#ifdef __cplusplus
#import "baseapi.h"
using namespace tesseract;
#else
#class TessBaseAPI;
#endif
#interface OCRDisplayViewController : UIViewController
<UIActionSheetDelegate, UINavigationControllerDelegate, MFMailComposeViewControllerDelegate, UIImagePickerControllerDelegate> {
TessBaseAPI *tess;
UIImage *imageForOCR;
NSString *outputString;
UIActivityIndicatorView *activityView;
IBOutlet UIBarButtonItem *cameraButton;
IBOutlet UIBarButtonItem *actionButton;
IBOutlet ZoomableImage *thumbImageView;
IBOutlet UILabel *statusLabel;
IBOutlet UITextView *outputView;
}
#property(nonatomic,retain)NSString *outputString;
#property(nonatomic,retain)IBOutlet UITextView *outputView;
#property(nonatomic,retain)IBOutlet UIBarButtonItem *cameraButton;
#property(nonatomic,retain)IBOutlet UIBarButtonItem *actionButton;
#property(nonatomic,retain)IBOutlet ZoomableImage *thumbImageView;
#property(nonatomic,retain)IBOutlet UILabel *statusLabel;
#end
I think the misstake in line (because it's cpp)
#import "baseapi.h"
try this and type semicollons manually!!!
#include "baseapi.h"
the file should be in red color.
I'm new with Core Data and there are some issues that I don't understand yet.
I have a entity called GCS (a subclass of NSManagedObject for Core Data):
#implementation GCS
#dynamic eye;
#dynamic ...
#dynamic ...
It works fine with Core Data when I do this:
GCS *failedBankDetails = [NSEntityDescription
insertNewObjectForEntityForName:#"GCS"
inManagedObjectContext:context];
failedBankDetails.eye = [NSNumber numberWithInt:12];
But then, in another class I have a property of GCS type:
#interface ModelManager : NSObject
{
GCS *tempGCS;
}
#property (nonatomic, retain) GCS *tempGCS;
...
In a method of ModelManager I tried this:
tempGCS.eye = [NSNumber numberWithInt:0];
But raised exceptions:
Failed to call designated initializer on NSManagedObject class 'GCS'
-[GCS setEye:]: unrecognized selector sent to instance 0x4d32ac0
Why cant I use the dot notation now? I think the #dynamic is the clue, but I shouldn't change it because I need to use it for Core Data, right?
Please help me and sorry for my english.
Thanks!
Dot notation has nothing to do with it, you'd get the same error if you called [tempGCS setEye:...]. The error is that you neglected to call initWithEntity:insertIntoManagedObjectContext: when creating the object in tempGCS; in particular, [[GCS alloc] init] will not work correctly.
I'm trying to get the first letter of an attribute (autor) from my pre populated sqlite database. I have no problems retriving data from the database using coredata. But when I try to get data from my transient property, I get this error message: "NSFetchedResultsController ERROR: object { Autor = "\U00cdtalo Calvino"; } returned nil value for section name key path 'FirstLetter'. Object will be placed in unnamed section"...
I have created a transient attribute called FirstLetter and inside my entity Cit. I have also my class for the entity defined.
Cit.h
#interface Cit : NSManagedObject {
#private
}
#property (nonatomic, retain) NSString * Autor;
#property (nonatomic, retain) NSString * FirstLetter;
- (NSString *) FirstLetter;
#end
Cit.m
#import "Cit.h"
#implementation Cit
#dynamic Autor;
#dynamic FirstLetter;
- (NSString *) FirstLetter {
NSLog(#"doing");
[self willAccessValueForKey:#"FirstLetter"];
NSString * initial = [[self valueForKey:#"Autor"] substringToIndex:1];
[self didAccessValueForKey:#"FirstLetter"];
return initial;
}
#end
I cannot get the it to work. Does anyone have a solution for that??? thanks!
I did something similar in my model class, but I didn't bother creating a transient object in the model. I just added a - (NSString *)sectionIndex method to my model that returned the first letter of the string, same as you.
So, I'd try deleting the transient attribute from your model and see if that works any better.
the problem I am trying to solve in an application that is using Core Data is to be able to hold a calculated value in a NSManagedObject custom ivar. The calculated value that I want to store is in fact an image. I do not want to persist these images; I build them and destroy them throughout the lifetime of the application. I tried along the lines of:
#interface RTStaffImage : NSManagedObject {
UIImage *image;
}
// Custom properties
#property (nonatomic, retain) UIImage *image;
// Managed object properties
#property (nonatomic, retain) NSNumber *imageID;
#property (nonatomic, retain) NSString *imageName;
and custom accessors methods:
- (void)setImage (UIImage*)im;
- (UIImage *)image;
and in the implementation:
#implementation RTStaffImage
#synthesize image;
#dynamic imageID;
#dynamic imageName;
This fails at runtime with unrecognised selector problems:
-[NSManagedObject setImage:]: unrecognized selector sent to instance
The above approach is what Apple (or, at least as far as I see having read the docs) outlines for transient properties so it should work :-(
Any ideas, comments?
- (void)setImage (UIImage*)im;
you are missing a colon between setImage and (UIImage*). This is the correct version:
- (void)setImage:(UIImage*)im;
And where are the implementations of those two methods?
-[NSManagedObject setImage:]: unrecognized selector sent to instance
just curious, I read NSManagedObject there, are you sure you create an instance of RTStaffImage there?
Yeah, you have these backwards:
#synthesize image;
#dynamic imageID;
#dynamic imageName;
You're providing an implementation for setImage and image, so image should be #dynamic, and the others you need synthesized methods for, so use #synthesize for imageID and imageName.
Good point, they should all be #dynamic since you're with CoreData.
2nd attempt: you have set RTStaffImage as the Class name in the Entity, right?
3rd attempt: is RTStaffImage.m actually part of the Target being built?