Getting image name from uiimageview - ios4

I want to get the particular image name by touching inside of that image. Can any one give me the sample code for that?

Nick Weaver is correct. There is still a way to do it, though.
Create an array with the names of the images. Set the tag property of each UIImageView so it corresponds to the names in the array. Then, access the array via the tag property.
NSArray *nameArray = [NSArray arrayWithObjects:#"image1", #"image2", nil];
//touch happened
NSString *imageName = [nameArray objectAtIndex:imageView.tag];
Another method is creating a UIImageView subclass.

UIImageView nor UIImage do store the name of the image you have used to create the image. You can subclass UIImageView and use your own initializer and an extra field to store the name.

Related

Use core data to send email with string

I have set up a core data model and I would like the ability to be able to tap on an entry and have an blank email pop up with the core data contents included. here is my code for saving the data-
NSManagedObject *newDevice = [NSEntityDescription insertNewObjectForEntityForName:#"Device" inManagedObjectContext:context];
NSNumber *timetickNumber = [NSNumber numberWithInt:timeTick];
NSString *versionString = [NSString stringWithFormat:#"Minutes of %#", self.versionTextField.text];
[newDevice setValue:timetickNumber forKey:#"name"];
[newDevice setValue:versionString forKey:#"version"];
[newDevice setValue:self.companyTextField.text forKey:#"company"];
Thanks in advance!
You can't click (or tap) on a Core Data object, because they do not have any UI and do not respond to UI events. The general flow you want is probably something like:
Figure out what UI element should trigger the email action-- a button, or a table row, or whatever UI element you're using.
In the handler method for taps on that element, create the MFMailComposeViewController. Where this happens depends on what UI element you're using. If your UI element is a button, this happens in whatever method your button calls when tapped. If the UI element is a table row, you probably want to use tableView:didSelectRowAtIndexPath: in your table view's delegate.
In that same method, get a reference to the managed object you want to send. If you fetched it (or created it) earlier, you might already have an instance var that points to it. If not, you may need to fetch it here.
Before displaying the MFMailComposeViewController, configure either the message body (via setMessageBody:isHTML:) or the attachment (via addAttachmentData:mimeType:fileName:) to contain the data from your managed object's data
Display the mail compose view to the user.

create a global NSMutableArray

I have a lot of View Controller and all use the same Class (ViewController).
In ViewController.m I have this code:
- (void)viewDidLoad
{
[super viewDidLoad];
pedidoNomeArray = [[NSMutableArray alloc] init];
pedidoValorArray = [[NSMutableArray alloc] init];
}
and when I go to View Controller number 2 my array pedidoNomeArray and pedidoValorArray are null.
What I have to do to use the same array in all my View Controllers?
thanks
One reason could be that you are not using ARC. In this case you assign the newly initialized array directly to an ivar, i.e. without using a setter. In this case, the array is not retained, and released as soon as your app enters the run loop. So, if you are not using ARC, use pedidoNomeArray = [[[NSMutableArray alloc] init] retain]; instead. But you should really use ARC since it avoids most of the common memory management problems.
EDIT (due to you comment):
Now it seems to me that what you need is a data model according to the MVC software architecture pattern. Your data are stored in an independent object, and both of your view controllers have a reference to this object. Your data model, which contains your "global array" could be instantiated e.g. in your application delegate or your root view controller, this is debatable, examples and discussion see here. I hope this helps.

subclass NSWindowController Core Data

I have a newb question, which I have tried unsuccessfully to find answers for on the web. The task is simple: I want to create a core data document-based app but alter the values in some label objects. Using interface builder, I can build the core data model and populate it, using an array controller, table, etc. all without writing any code. So far so good. My test example is to build a core data model with Box entities that have length and width attributes. I would like a label to display the area, i.e. length*width for any geometrically challenged :).
So after browsing around, I've decided I need to create an NSWindowController subclass and use that to update the label when a box in the table is selected. Have attempted this, but have failed. Before I even hook up the label to the window controller, I have a problem. Following the template comments, I added this to Document.m:
- (void)makeWindowControllers
{
NSLog(#"Adding custom Window Controller");
MyWindowController* myWindowController = [[MyWindowController alloc] init];
[self addWindowController:myWindowController];
}
Also added this to the template MyWindowController.m:
- (id)init
{
self = [super initWithWindowNibName:#"MyWindowController"];
return self;
}
The window controller has its own NIB file from Interface builder where I put the table and label etc. The file owner is set to MyWindowController. Probably forgetting other things, but that's what I remember for now.
The log message appears at startup, but then I get an exception "this class is not key value coding-compliant for the key managedObjectContext" before the window appears. I'm guessing that I don't have the window controller hooked up to the document class properly? My other thought is that the array controller is in the window controller nib, not the document nib, so maybe it's looking in the wrong place for the managedObjectContext?
I would try a different approach: Add area to your Box entity as a read-only attribute. Auto-create a Box class with Xcode ("Create NSManagedObject Subclass" menu item in the "Editor" menu when viewing the data model), then add this to Box.h
#property (weak, readonly) NSString * area;
and this to Box.m
- (NSNumber *)area
{
return [NSNumber numberWithDouble:([[self length] doubleValue] - [[self width] doubleValue])];
}
+ (NSSet *)keyPathsForValuesAffectingArea
{
return [NSSet setWithObjects:#"length", #"width", nil];
}
If you do this you can just bind area to a label value like you do for the other Box properties. No need to subclass NSWindowController or watch for changes.

How to save a UIImageView to a CoreData Database

What is the SIMPLEST way to save a UIImageView to a CoreData Database. I have tried this:
Save:
UIImage *image = imageView.image;
NSData *imageData = UIImagePNGRepresentation(image);
[newContact setValue:imageData forKey:#"imageViewFinal"];
Retrive:
imageView.image = [matches valueForKey:#"imageViewFinal"];
and I have added an Attribute called 'imageViewFinal' with a Binary Data type.
PROBLEM:
When I go to build it and click the save button, the app crashes, what's the problem?
Thanks, Seb.
What #ShermanLo said is right, the crash log shows that you've modified your model but did not handle the conflict between the old & new store model versions in the right way.
So just delete your App in your device/simulator, and rebuild/run it.
Note: Whenever you've modified your models, you need to do it this way unless you offer an approach to handle. There're many related QAs on SO. :)

How do i attach image form ui view to email body

I have a small ui view that alows user to select a pic form camera roll, i want to attach it along with my text fields in email.
.h
#property (strong, nonatomic) IBOutlet UIImageView *imageView;
.m
NSString *emailBody = [NSString stringWithFormat:#(textboxes and other outlets are here)"%#"imageView.image];
When emailed I get the text strings attached but not the image? Coul dsomeone point me in the right direction on this, thanks
xcode 4.3
try this link to send images by email
http://iosdevelopertips.com/email/how-to-send-email-with-attachments-example-using-iphone-camera-to-email-a-photo.html
if that is not what u want u may have to convert image to nsdata using the functions
NSData *data=UIImageJPEGRepresentation(image, 1.0);
now convert this data to string by base64encoding and then attach to string.

Resources