I am a student who is learning and working on an App for my school. I have just started and am doing okay. However, I am recieveing the error "Expected identifier or '(' ". I have spent a few days now reading posts and googleing, and no solution I have found is working for me.
I am trying to make a Round Rect Button on the second tab of my application to link to the school's website.
Here is the .h:
#import <UIKit/UIKit.h>
#interface SecondViewController : UIViewController {
}
- (IBAction)Website:(id)sender;
#end
and here is my .m with error commented:
#import "SecondViewController.h"
#interface SecondViewController ()
#end
#implementation SecondViewController
-(IBAction)Website {
[[UIApplication sharedApplication ] openURL:[NSURL URLWithString:#"http://www.google.com"]];
}
{ **// Error is on this line[23]**
[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)Website;
- (IBAction)Website:(id)sender; {
}
#end
How can I fix this little guy? Thank you very much!
Also, the .h file was formed by xCode, by simply control dragging from button, to .h and creating an action. Could this be the cause?
I think you have accidentally deleted this line:
- (void)viewDidLoad
above this line
{ **// Error is on this line[23]**
but for simplicity you could delete this:
{ **// Error is on this line[23]**
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
as you are not using viewDidLoad for anything
Related
I have looked at other similar questions on this site, apple dev site and countless YouTube videos but I am still unable to figure this out. There seems to be very little info on getting a user's location in Xcode/iOS8.
I have a map view that works fine except when I click on a button to get my location, nothing happens and in the logs I see
Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.
I don't understand what I am doing wrong. I am very new to programming and all information I have seen doesn't make much sense to me.
I'm using storyboards in my app, and the code specific to this is as follows:
mapViewController.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
#interface mapViewController : UIViewController {
MKMapView *mapview;
}
#property (nonatomic, retain) IBOutlet MKMapView *mapview;
-(IBAction)setMap:(id)sender;
-(IBAction)getCurrentLocation:(id)sender;
#property (nonatomic, retain) IBOutlet CLLocationManager *locationManager;
#end
mapViewController.m
#import "mapViewController.h"
#interface mapViewController ()
#end
#implementation mapViewController {
CLLocationManager *locationManager;
}
#synthesize mapview;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.locationManager.delegate=self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.requestWhenInUseAuthorization;
}
- (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)getCurrentLocation:(id)sender {
mapview.showsUserLocation = YES;
}
#end
I've been struggling with this for so long I'm tearing my hair out. Can someone point out where I've gone wrong?
The error message is quite self-explained.
First of all, you didn't initialized CLLocationManager in your viewDidLoad. You can initialize with (before the delegate line):
self.locationManager = [[CLLocationManager alloc] init];
Then, you have to request for location service, using [self.locationManager requestWhenInUseAuthorization] or [self.locationManager requestAlwaysAuthorization]. (Not to forget to add corresponding usage description key in Info.plist).
Last, you have to check the response of authorization from user. If user denied the authorization, you shouldn't start any Location Service-related actions, until you ask again.
Update if you support iOS 7 as well, the codes will be slightly different.
One of the example projects in XCode 5 was named "Utility Application". It had a main view and an alternate view and set up an Info button to flip the main view to the alternate view. It used a viewcontroller delegate and a protocol definition to switch back from the flip view to the main view. In XCode 6 it is no longer there.
When I run this simple XCode 5 example app in XCode 6, I get a warning in the method below:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"showAlternate"]) {
[[segue destinationViewController] setDelegate:self]; //<<<< Here is where the warning appears
}
}
The warning is: Sending 'MainViewController *const_strong' to parameter of incompatible type 'id'
What is this? A bug? The app runs fine on both simulator and iOS device. Below is the entire code. Any help will be much appreciated.
**// MainViewController.h
#import "FlipsideViewController.h"
#interface MainViewController : UIViewController <FlipsideViewControllerDelegate>
#end
// MainViewController.m
#import "MainViewController.h"
#interface MainViewController ()
#end
#implementation MainViewController
- (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.
}
#pragma mark - Flipside View
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller
{
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"showAlternate"]) {
[[segue destinationViewController] setDelegate:self]; //<<<< Here is where the warning appears
}
}
#end
// FlipsideViewController.h
#import <UIKit/UIKit.h>
#class FlipsideViewController;
#protocol FlipsideViewControllerDelegate
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller;
#end
#interface FlipsideViewController : UIViewController
#property (weak, nonatomic) id <FlipsideViewControllerDelegate> delegate;
- (IBAction)done:(id)sender;
#end
// FlipsideViewController.m
#import "FlipsideViewController.h"
#interface FlipsideViewController ()
#end
#implementation FlipsideViewController
- (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.
}
#pragma mark - Actions
- (IBAction)done:(id)sender
{
[self.delegate flipsideViewControllerDidFinish:self];
}
#end**
You may have figured this out already...just wanted to post a link for for those stumbling upon this: getting a warning setting up delegate for a custom protocol
I've created a tabbed application and in that one tab is view controller with a map view. The other tab in the app works fine but when I try to switch to the tab with the mapView it crashes. I've currently set the mapView to show user's current location. Please let me know where I'm going wrong. below is the code for the view controller with map view.
SecondViewcontroller.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
#interface SecondViewController : UIViewController <MKMapViewDelegate>
#property (weak, nonatomic) IBOutlet MKMapView *mapView;
#end
SecondViewcontroller.m
#import "SecondViewController.h"
#interface SecondViewController ()
#end
#implementation SecondViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[_mapView setDelegate:self];
[self.mapView setShowsUserLocation:YES];
}
-(void)viewWillDisappear:(BOOL)animated
{
[_mapView setShowsUserLocation:NO];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Image of crash report
I am following a tutorial on here which consist of Event management with notifications and all. Now the problem is that i am getting errors in the following Codes
My .h file
#import <UIKit/UIKit.h>
#import <EventKit/EventKit.h>
#interface ViewController : UIViewController
- (IBAction) NewEvent:(id)sender;
#end
My .m file
#import "ViewController.h"
#import <EventKit/EventKit.h>
#interface ViewController ()
#end
#implementation ViewController
- (IBAction) NewEvent:(id)sender {
EKEventStore *eventDB = [[EKEventStore alloc] init];
EKEventStore *myEvent = [EKEvent eventWithEventStore:eventDB];
myEvent.title = #"New Event"; // <-- Errors are appearing hear as shown in the title.
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
#end
Additional information:
i have already added the frame work but still getting error as show above in the code. The name of the code is
the property 'title' was not found on object of type "eventstore"
Thank you in advance :)
You'll want to double-check that myEvent is the right type (EKEvent * rather than EKEventStore *) and that you're actually trying to set the title on myEvent rather than eventDB. The error you posted indicates that you're setting title on an event store, instead of just an event.
I'm working on a game for the iPad, and I have it start up with a menu screen. For a while, the menu screen would come up just fine in the simulator. I'm using the main view controller that xcode provides when starting up a view-based application. But, unfortunately, I accidentally cut off the connection between the UIView and the view controller in interface builder, and after reconnecting it, the screen comes up as blank now. It works fine when I simulate the screen in interface builder, but not when running in xcode. Here's the code for the view controller:
//
// FunctionMachineViewController.h
// FunctionMachine
//
// Created by Kameron Schadt on 5/24/11.
// Copyright 2011 Willamette University. All rights reserved.
//
#import <UIKit/UIKit.h>
#interface FunctionMachineViewController : UIViewController {
IBOutlet UITextField* equation;
IBOutlet UISlider* startLevel;
IBOutlet UITextView* startLevelNumber;
}
- (IBAction) startOnePlayer:(id)sender;
- (IBAction) startTwoPlayer:(id)sender startingEquation:(NSString*)equationUsed;
- (IBAction) sliderValueChanged:(UISlider*)sender;
#property(nonatomic, retain) IBOutlet UISlider* startLevel;
#property(nonatomic, retain) IBOutlet UITextField* equation;
#property(nonatomic, retain) IBOutlet UITextView* startLevelNumber;
#end
//
// FunctionMachineViewController.m
// FunctionMachine
//
// Created by Kameron Schadt on 5/24/11.
// Copyright 2011 Willamette University. All rights reserved.
//
#import "FunctionMachineViewController.h"
#import "GameViewController.h"
#implementation FunctionMachineViewController
#synthesize equation, startLevel, startLevelNumber;
- (IBAction)sliderValueChanged:(UISlider*)sender {
[startLevelNumber setText:[NSString stringWithFormat:#" %.1f", [sender value]]];
}
-(IBAction)startOnePlayer:(id)sender
{
GameViewController* GameView = [[GameViewController alloc] initWithNibName:nil bundle:nil];
[GameView isOnePlayer:YES];
[self presentModalViewController:GameView animated:YES];
}
-(IBAction)startTwoPlayer:(id)sender startingEquation:(NSString*)equationUsed
{
GameViewController* GameView = [[GameViewController alloc] initWithNibName:nil bundle:nil];
[GameView isOnePlayer:NO];
[self presentModalViewController:GameView animated:YES];
}
- (void)viewDidLoad {
[super viewDidLoad];
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (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 {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
#end
I didn't really see any problem here, so I'm assuming it has something to do with me reconnecting the view controller to the view. I don't have an actual view file that I'm using, just the viewcontroller. Can anybody help?
Check the setting of "Main nib file base name" in [YourApp]-info.plist, in the "Supporting Files" folder – if you've changed the name of your root view controller, you may need to change the name here as well.
For some odd reason my Referencing outlet for the App Delegate was disconnected.
Try creating a referencing outlet from delegate to File's Owner using the connections inspector (farthest right menu) for your App Delegate.