Expected identifier image - xcode

Hi i am new here and also a noob with Xcode please help.
I am trying to make Imagepickercontroller but i am having trouble with one error and don't know how to solve it.
Viewcontroller.h
#interface ViewController : UIViewController<UIImagePickerControllerDelegate> {
IBOutlet UIButton *button;
IBOutlet UIImageView *image;
UIImagePickerController *imagepicker;
}
- (IBAction)change:(id)sender;
#end
Viewcontroller.m
#interface ViewController ()
#end
#implementation ViewController
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *mytouch = [[event allTouches] anyObject];
button.center = [mytouch locationInView:self.view];
}
- (void)viewDidLoad
{
[super viewDidLoad];
imagepicker = [[UIImagePickerController alloc] init];
[imagepicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[imagepicker setAllowsEditing:YES];
}
- (IBAction)change:(id)sender
{
[self presentViewController:imagepicker animated:YES completion:NO];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[UIImage(setimage:)image];
[self dismissViewControllerAnimated:YES completion:NO];
}
#end
Expected identifier [UIImage(setimage:)image];

[UIImage(setimage:)image] needs to be [someImageView setImage:image]
Where someImageView is an instance of UIImageView

Note that UIImage is a class, not a object. You should give a class method of UIImage without any parenthesis.
In addition, setImage: is not a class method of UIImage. I guess, you mean a object instance, not the class object.

Related

Core Loation not outputing current location

I've been working on a app that displays the current location of the user in a UILabel using the core location framework in Xcode When a button is clicked the app calls the CLLocationManager that gets the users latitude and longitude. I also included reverse geocoding to present the coordinates in a human readable form. I have this code here.
Header file
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#interface ViewController : UIViewController <CLLocationManagerDelegate>
#property (strong, nonatomic) IBOutlet UILabel *latitudeLabel;
#property (strong, nonatomic) IBOutlet UILabel *longitudeLabel;
#property (strong, nonatomic) IBOutlet UILabel *addressLabel;
- (IBAction)getCurrentLocation:(id)sender;
#end
Implementation file
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController {
CLLocationManager *locationManager;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
locationManager = [[CLLocationManager alloc] init];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)getCurrentLocation:(id)sender {
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
}
#pragma mark - CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(#"didFailWithError: %#", error);
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle:#"Error" message:#"Failed to Get Your Location" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[errorAlert show];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(#"didUpdateToLocation: %#", newLocation);
CLLocation *currentLocation = newLocation;
if (currentLocation != nil) {
_longitudeLabel.text = [NSString stringWithFormat:#"%.8f", currentLocation.coordinate.longitude];
_latitudeLabel.text = [NSString stringWithFormat:#"%.8f", currentLocation.coordinate.latitude];
}
}
#end
I got this output
Message from debugger: Terminated due to signal 15

xcode How to link UIAlertview action to another viewcontroller?

Im am trying to link one of my buttons from the UIAlertView that pops up so that It changes to another viewcontroller. Basically, the cancel already works, but when Next is clicked it doesnt, and i don't know how to link to another viewcontroller. Please help.
#import "ViewController.h"
#interface ViewController() <UIAlertViewDelegate>
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)clickButton:(id)sender {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: #"Test" message: #"Message" delegate: self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Redeem", nil];
[alert show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if(buttonIndex == 1){ //Next
UIViewController* newView = [[UIViewController alloc] init];
[self presentViewController:newView animated:YES completion:nil];
}
}
#end
It is working...Just create object of viewcontroller that you want to present instead of
UIViewController* newView = [[UIViewController alloc] init];
like
SecondViewController * newView = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
if you are using xib.
Or
SecondViewController * newView = [self.storyboard instantiateViewControllerWithIdentifier:#"SecondViewController"];
if you are using storyboard(if you want to go through coding).
and then write
[self presentViewController:newView animated:YES completion:nil];
line.

How take a picture from camera of iPhone - iOS 7

my program always an error of threads.
error that appears at compile time
http://imgur.com/6rGkwKd
1. My .h
import
#interface PerfilViewController : UIViewController
<UIImagePickerControllerDelegate,UINavigationControllerDelegate>
#property (weak, nonatomic) IBOutlet UIImageView *fotoPerfil;
#property (weak, nonatomic) IBOutlet UIButton *botaoSalvarFoto;
#property (nonatomic) UIImagePickerController *pegarFoto;
-(IBAction)salvarFoto:(UIButton *)sender;
#end
2. My .m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
_pegarFoto = [[UIImagePickerController alloc]init];
_pegarFoto.delegate = self;
_pegarFoto.sourceType = UIImagePickerControllerSourceTypeCamera;
}
-(IBAction)salvarFoto:(UIButton *)sender {
[self presentViewController:_pegarFoto animated:YES completion:nil];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo {
_fotoPerfil.image = img;
[[picker parentViewController] dismissViewControllerAnimated:YES completion:nil];
}

blank screening after going back

I've recently created a app with Xcode. When 2 images collide, it sends me to a new screen (which is good). However, when i push the button to return me back to the original view, it goes blank. Can you tell me why? Any feed back is appreciated.
Here is code from the First .h file:
import
#interface ViewController : UIViewController {
IBOutlet UIImageView *image1;
IBOutlet UIImageView *image2;
}
#property (nonatomic, retain) UIImageView *image1;
#property (nonatomic, retain) UIImageView *image2;
-(void)collision;
#end
And from the .m:
import "ViewController.h"
import "newview.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize image1, image2;
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *mytouch = [[event allTouches] anyObject];
image1.center = [mytouch locationInView:self.view];
[self collision];
}
-(void)collision {
if (CGRectIntersectsRect(image1.frame, image2.frame)) {
newview *second = [[newview alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:second animated:YES];
}
}
here is code from the second .h (The one with the go back button):
(IBAction)retry:(id)sender;
and from the .m:
import "newview.h"
import "ViewController.h"
#interface newview ()
#end
#implementation newview
(IBAction)retry:(id)sender {
ViewController *second = [[ViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:second animated:YES];
}
The blank screen is another modal view from (IBAction)retry:(id)sender.
You should use [self dismissModalViewControllerAnimated:YES]; in (IBAction)retry:(id)sender for going back to previous screen instead of presenting another modal view.

UIWebView Delegate Code Doesn't Seem Right

I've implemented sample code using the UIWebView that I found, but it doesn't look right to me, though it works. Specifically because it sets the UIWevView delegate twice (in viewDidLoad and viewWillAppear). Also, myWebView is set as an autorelease object, but then it's released in dealoc. I'm hoping someone can tell me how to clean this up.
// *** WebViewController.h ***
#interface WebViewController : UIViewController
<UIWebViewDelegate>
{
UIWebView *myWebView;
UIActivityIndicatorView *activityIndicator;
}
#property (nonatomic, retain) UIWebView *myWebView;
#property (nonatomic, retain) UIActivityIndicatorView *activityIndicator;
#end
// *** WebViewController.m ***
#synthesize myWebView;
- (void) viewDidLoad {
[super viewDidLoad];
// - - - - -> Create the UIWebView
CGRect webFrame = [[UIScreen mainScreen] applicationFrame];
webFrame.origin.y += 42.0;
webFrame.size.height -= 106.0;
self.myWebView = [[[UIWebView alloc] initWithFrame:webFrame] autorelease];
self.myWebView.backgroundColor = [UIColor whiteColor];
self.myWebView.scalesPageToFit = YES;
self.myWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
self.myWebView.delegate = self;
[self.view addSubview: self.myWebView];
// - - - - -> Create the UIActivityIndicatorView
self.activityIndicator = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite] autorelease];
[self.view addSubview: self.activityIndicator];
self.activityIndicator.center = CGPointMake(135,438);
[self.myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.someURL.com/"]]];
- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.myWebView.delegate = self;
}
- (void) viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.myWebView stopLoading];
self.myWebView.delegate = nil;
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
- (void) dealloc {
myWebView.delegate = nil;
[myWebView release];
[activityIndicator release];
[super dealloc];
}
It's pretty much fine to do that. The idea is pretty basic. You do not want the delegate to receive any delegation messages when off screen. So the idea of setting the delegate -viewWillAppear: and -viewWillDisappear: is correct. But I don't see any delegate methods being implemented in the code.

Resources