PDA

View Full Version : synthesize help




uaecasher
Nov 28, 2009, 03:14 PM
when I try to synthesize a property i get this error:



no declaration of property 'imgPicker2' found in the interface



I did declare it:



#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

@interface testPickerViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIActionSheetDelegate> {
IBOutlet UIButton *button;
IBOutlet UIButton *upload;
IBOutlet UIButton *cambutton;
IBOutlet UITextView *myTextField;
IBOutlet UIImageView *image;
UIImagePickerController *imgPicker;
UIImagePickerController *imgPicker2;

}




- (IBAction)grabImage;
- (IBAction)grabimage2;
- (IBAction)uploadImage;


@property (nonatomic, retain) UIImagePickerController *imgPicker;
@property (nonatomic, retain) UIImagePickerController *imgPicker2;



drf1229
Nov 28, 2009, 03:23 PM
You have to also declare it in your class (.m) file. Declare it like this:

@implementation Class
@synthesize propertyname;
@end

Darkroom
Nov 28, 2009, 03:29 PM
is that exactly how your header file is written? if so, it's missing @end.

also, i'm not sure why you are importing foundation?

uaecasher
Nov 28, 2009, 03:38 PM
You have to also declare it in your class (.m) file. Declare it like this:

@implementation Class
@synthesize propertyname;
@end

I did it like that:



@implementation testPickerViewController

@synthesize imgPicker;
@synthesize imgPickerCam;


.....

@end




and yes the @end was there for the header file, for the foundation I'm not sure why it's there lol, can't remember, nothing happens if I removed it though

Darkroom
Nov 28, 2009, 07:48 PM
i'm pretty sure you have a typo. it should be obvious. if you can't find it just post your .h and .m files here as they appear in your program.

uaecasher
Nov 29, 2009, 03:20 AM
here you go:




#import <UIKit/UIKit.h>

@interface testPickerViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIActionSheetDelegate> {
IBOutlet UIButton *button;
IBOutlet UIButton *upload;
IBOutlet UIButton *cambutton;
IBOutlet UITextView *myTextField;
IBOutlet UIImageView *image;
UIImagePickerController *imgPicker;
UIImagePickerController *imgPickerCam;

}




- (IBAction)grabImage;

- (IBAction)uploadImage;


@property (nonatomic, retain) UIImagePickerController *imgPicker;
@property (nonatomic, retain) UIImagePickerController *imgPickerCam;

@end








#import "testPickerViewController.h"

@implementation testPickerViewController

@synthesize imgPicker;
@synthesize imgPickerCam;



- (void)viewDidLoad {
self.imgPicker = [[UIImagePickerController alloc] init];
self.imgPicker.allowsImageEditing = NO;
self.imgPicker.delegate = self;
self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}

- (IBAction)grabImage {
[self presentModalViewController:self.imgPicker animated:YES];

}





- (IBAction)uploadImage {
/*
turning the image into a NSData object
getting the image back out of the UIImageView
setting the quality to 90
*/
NSData *imageData = UIImageJPEGRepresentation(image.image, 90);
// setting up the URL to post to
NSString *urlString = @"http://mozymac.com/upload.php";

// setting up the request object now
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];

/*
add some header info now
we always need a boundary when we post a file
also we need to set the content type

You might want to generate a random boundary.. this is just the same
as my output from wireshark on a valid html post
*/
NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];

/*
now lets create the body of the post
*/
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"userfile\"; filename=\".jpg\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:imageData]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
// setting the body of the post to the reqeust
[request setHTTPBody:body];

// now lets make the connection to the web
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];


myTextField.text = (returnString);


}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo {
image.image = img;
[[picker parentViewController] dismissModalViewControllerAnimated:YES];

// need to show the upload image button now
upload.hidden = NO;
}

@end

Darkroom
Nov 29, 2009, 06:05 AM
is your .h and .m files in your classes folder called testPickerViewController.h and testPickerViewController.m?

is that the only error message you receive, or are there also lots of others?

uaecasher
Nov 29, 2009, 06:52 AM
is your .h and .m files in your classes folder called testPickerViewController.h and testPickerViewController.m?

is that the only error message you receive, or are there also lots of others?

yes they are my .h and .m, and yes it's the only error message I get.

uaecasher
Nov 29, 2009, 07:01 AM
is your .h and .m files in your classes folder called testPickerViewController.h and testPickerViewController.m?

is that the only error message you receive, or are there also lots of others?

wanna remote control my computer :D? although I'm 110% sure this is my code.

drf1229
Nov 29, 2009, 09:52 AM
When I copy and pasted the code you gave on my computer it worked just fine. Double check the code you posted and the code you have are exactly the same.

uaecasher
Nov 29, 2009, 11:24 AM
When I copy and pasted the code you gave on my computer it worked just fine. Double check the code you posted and the code you have are exactly the same.

did you compile for iphone device or simulator? for me it works for iphone (i only get dev id error because I don't have my activation email) but for simulator i get that error.

drf1229
Nov 29, 2009, 11:28 AM
I just built it, didn't run it. You shouldn't get that error when you run it and NOT when you build it. Try just building it. Then make sure the OS you are running the simulator with is 3.0 or higher.

uaecasher
Nov 29, 2009, 11:39 AM
I just built it, didn't run it. You shouldn't get that error when you run it and NOT when you build it. Try just building it. Then make sure the OS you are running the simulator with is 3.0 or higher.


I just tried to just build (command + b) i get same error:

Code Sign error: The identity 'iPhone Developer' doesn't match any valid certificate/private key pair in the default keychain

drf1229
Nov 29, 2009, 12:17 PM
Oh well thats completely different from the error you posted earlier! That means that there is no provisioning profile on your device that matches the one in your target file.

uaecasher
Nov 29, 2009, 12:22 PM
That means that there is no provisioning profile on your device that matches the one in your target file.

could you simplify please and how could I solve it?

drf1229
Nov 29, 2009, 02:19 PM
Yes. I figured you'd ask that :) . The provisioning profile on your ipod that lets you run your app is either missing or different than the one in xcode.

To change the selected profile in Xcode:

1. Right click your app under "Targets" and click "Get Info".
2. Search "Code signing identity".
3. On the right column choose the profile that matches your iPod from the drop down box.

To add or delete profiles on your iPod:

1. At the top of the screen click Window->Organizer.
2. Click on "Provisioning Profiles".
3. Drag the profile to your device.
4. To view and delete profiles, click on your device in the organizer

Knock yourself out!

uaecasher
Nov 30, 2009, 01:21 AM
Yes. I figured you'd ask that :) . The provisioning profile on your ipod that lets you run your app is either missing or different than the one in xcode.

To change the selected profile in Xcode:

1. Right click your app under "Targets" and click "Get Info".
2. Search "Code signing identity".
3. On the right column choose the profile that matches your iPod from the drop down box.

To add or delete profiles on your iPod:

1. At the top of the screen click Window->Organizer.
2. Click on "Provisioning Profiles".
3. Drag the profile to your device.
4. To view and delete profiles, click on your device in the organizer

Knock yourself out!

back to point one, I now get the undeclared error, could it be something wrong with my xcode version or something? (this is really frustrating :()

thanks for help guys

North Bronson
Nov 30, 2009, 03:02 AM
back to point one, I now get the undeclared error, could it be something wrong with my xcode version or something? (this is really frustrating :()

thanks for help guys

Maybe it's just Xcode's time of the month.

Clean your targets. Just go ahead and delete your builds directory.

Export your header and implementation files and delete them from your project.

Import your header and implementation files back into your project.

Sometimes this sort of stuff cleans up these weird phantom bugs on my end.

uaecasher
Nov 30, 2009, 03:24 AM
Maybe it's just Xcode's time of the month.

Clean your targets. Just go ahead and delete your builds directory.

Export your header and implementation files and delete them from your project.

Import your header and implementation files back into your project.

Sometimes this sort of stuff cleans up these weird phantom bugs on my end.

no use :(

North Bronson
Nov 30, 2009, 03:39 AM
What if you replaced:

- (void)viewDidLoad {
self.imgPicker = [[UIImagePickerController alloc] init];
self.imgPicker.allowsImageEditing = NO;
self.imgPicker.delegate = self;
self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}

- (IBAction)grabImage {
[self presentModalViewController:self.imgPicker animated:YES];

}

with:

//- (void)viewDidLoad

- (IBAction)grabImage
{
UIImagePickerController *newImgPicker = [[UIImagePickerController alloc] init];

[newImgPicker setAllowsImageEditing: NO];

[newImgPicker setDelegate: self];

[newImgPicker setSourceType: UIImagePickerControllerSourceTypePhotoLibrary];

[self presentModalViewController: newImgPicker animated: YES];

[newImgPicker release];
}

Then, you're not keeping this image picker around after you're done using it and you get around this problem with the variables.

As long as you're not using those image pickers anywhere else, I would just go with this approach and not declare them as instance variables for your class.

uaecasher
Nov 30, 2009, 04:25 AM
OMG, there was a 1.4MB update in software update so I though I would install it. NOW IT WORKS!!

lol thanks for the help guys :D