When I am running my app in iPhone for testing, SIM and WiFi network is connecting and disconnecting again and again. But in normal condition and running other app it is working fine?
I am using GPS and Map services in my app.
1)Problem in code?
2)Problem in iPhone?
3)Other?
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
#interface MainViewController : UIViewController<CLLocationManagerDelegate,
MKMapViewDelegate>
#property (strong, nonatomic) IBOutlet UIView *mapView;
#property (strong, nonatomic) CLLocationManager *locationManager;
#property (strong, nonatomic) IBOutlet MKMapView *mkMap;
#property (strong, nonatomic) CLLocation *myCurrentLocation;
- (IBAction)mapView:(id)sender;
- (IBAction)mapToMain:(id)sender;
#end
#import "MainViewController.h"
#import <MapKit/MapKit.h>
#interface MainViewController ()
#end
#implementation MainViewController
#synthesize mapView;
#synthesize mkMap;
#synthesize myCurrentLocation;
#synthesize locationManager;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
//start core location services
if(self.locationManager == nil)
{
locationManager=[[CLLocationManager alloc] init];
}
locationManager.delegate=self;
locationManager.desiredAccuracy=kCLLocationAccuracyBestForNavigation;
[locationManager startUpdatingLocation];
mkMap.showsUserLocation=YES;
myCurrentLocation=mkMap.userLocation.location;
}
#pragma mark- core location delgate method
-(void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
NSLog(#"locationUpdated");
NSLog(#"%#",[locations lastObject]);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)mapView:(id)sender {
[self.view addSubview:mapView];
}
- (IBAction)mapToMain:(id)sender {
[mapView removeFromSuperview];
}
#end
Check ANY OTHER Maps App on your device; if the same problem persists, then your device may have problem.
If same problem is occurring in this app, (Which is your case); AND MAP that is provided by Iphone is not giving the problem.
THEN, Consider checking the same App, you downloaded from AppStore for checking purpose, on some other device and see if the same problem persist.
If the problem does not exist on other devices then, your device is problematic.
If the problem does exist on other devices then, code you wrote is problematic.
Related
I am trying to implement 2 Web views using the storyboard, both linked to another online webpage.
For some reason I don't get any errors, but only the PricesViewController works.
The other VC generates a white page......
I am using these 4 files:
PricesViewcontroller.h
#import <UIKit/UIKit.h>
#interface PricesViewController : UIViewController
{
IBOutlet UIWebView *WebView; }
#property (nonatomic, retain) UIWebView *WebView;
#end
PricesViewController.m
#import "PricesViewController.h"
#interface PricesViewController ()
#end
#implementation PricesViewController #synthesize WebView;
- (void)viewDidLoad {
[WebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.sparein.be/full_pricelist.pdf"]]];
[super viewDidLoad];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self; }
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated. }
#end
ReservationsViewController.h
#import <UIKit/UIKit.h>
#interface ReservationsViewController : UIViewController
{
IBOutlet UIWebView *WebView2; }
#property (nonatomic, retain) UIWebView *WebView2;
#end
ReservationsViewController.m
#import "ReservationsViewController.h"
#interface ReservationsViewController ()
#end
#implementation ReservationsViewController #synthesize WebView2;
- (void)viewDidLoad {
[WebView2 loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.google.be"]]];
[super viewDidLoad];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self; }
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated. }
#end
This may not fix your problem, but try this. Change your PricesViewController.h and ReservationsViewController.h similarly. Also, what version of Xcode are you using, and what version of iOS are you targeting? You shouldn't need #synthesize in your .m if you're using a recent version of Xcode and iOS.
#interface PricesViewController : UIViewController
#property (nonatomic, weak) IBOutlet UIWebView *WebView;
#end
IBOutlets should not be retained, as this can cause retain cycles. May not be the cause, but good programming practice anyway.
I am having trouble with a webview. This webview loads a webpage with some inputfields and some droplists. The problem is that the keyboard and the scroll wheel don't appear. I see a quick 'flash' and the cursor does go in the selected inputfield, but the keyboard doesn't appear.
I'm using xcode 4.3.3
My Appdelegate.h
#import <UIKit/UIKit.h>
#class ViewController;
#interface AppDelegate : UIResponder <UIApplicationDelegate> {
UIWindow *windowTB;
UIViewController *tabBarVC;
// UIWebView *homeWebView;
}
#property (strong, nonatomic) IBOutlet UIWindow *windowTB;
#property (strong, nonatomic) IBOutlet UIViewController *tabBarVC;
//#property (strong, nonatomic) IBOutlet UIWebView *homeWebView;
#end
Appdelegate.m (the relevant part)
#import "AppDelegate.h"
#import "tabBarVC.h"
#import "homeVC.h"
#implementation AppDelegate
#synthesize windowTB;
#synthesize tabBarVC;
//#synthesize homeWebView;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self.windowTB setRootViewController:tabBarVC];
[self.windowTB makeKeyAndVisible];
return YES;
}
The homeVC.h
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#interface homeVC : UIViewController <UIWebViewDelegate>{
IBOutlet UIWebView *homeWebView;
}
#property (nonatomic, retain) UIWebView *homeWebView;
#end
And last homeVC.m
#import "AppDelegate.h"
#import "homeVC.h"
#implementation homeVC
#synthesize homeWebView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
return self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidLoad
{
[super viewDidLoad];
[homeWebView loadRequest:[NSURLRequest requestWithURL: [NSURL URLWithString:#"http://rolfdeenen.nl/test.html"]]];
}
I have been searching for a about a day now, but it just doesn't make sence to me. Can anyone help me?
Thanx!
Maybe the problem is in your webpage, because the webview has a standard behavior and you can't modify it.
I am a very inexperienced developer and have run into a problem that should be easy however after hours of reading over Apple's Developer guide and many different questions on this site I am still stumped.
All I am trying to do is transition from my root view controller to my next view controller via a UIButton.
Here is appdelegate.h:
#import <UIKit/UIKit.h>
#class MainViewController;
#interface MDAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UINavigationController *navigationController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
#end
Important stuff from Appdelegate.m:
#import "MDAppDelegate.h"
#import "MainViewController.h"
#implementation MDAppDelegate
#synthesize window, navigationController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions (NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
MainViewController.h:
#import <UIKit/UIKit.h>
#interface MainViewController : UIViewController {
UIButton *cityButton;
}
#property (nonatomic, retain) IBOutlet UIButton *cityButton;
- (IBAction)chooseCityAction:(id)sender;
#end
And finally, MainViewController.m:
#import "MainViewController.h"
#import "DailyDealViewController.h"
#implementation MainViewController
#synthesize cityButton;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (void)dealloc
{
[cityButton release];
[super dealloc];
}
- (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.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
UIBarButtonItem *temporaryBarButtonItem = [[UIBarButtonItem alloc] init];
temporaryBarButtonItem.title = #"Back";
self.navigationItem.backBarButtonItem = temporaryBarButtonItem;
[temporaryBarButtonItem release];
}
- (void)viewDidUnload
{
[self setCityButton:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (IBAction)chooseCityAction:(id)sender {
DailyDealViewController *dailyDealViewController = [[DailyDealViewController alloc]initWithNibName:#"DailyDealViewController" bundle:nil];
[dailyDealViewController release];
[self.navigationController pushViewController:dailyDealViewController animated:YES];
}
#end
Here is the error:
2011-10-03 21:56:14.258 MD[4235:207] *** Terminating app due to uncaught exception
'NSUnknownKeyException', reason: '[<UIViewController 0x4b434c0>
setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key
cityButton.'
I would love to know what I missing.
You have released dailyDealViewController before pushing it. Move the release statement to after the pushViewController statement.
I want to make multi view application. My goal is when program launch to load first view controller and then when press the button to load new tab bar controller and dismiss first controller. I try myself and I do firt step, but when tab bar controller is loaded it's appear only small tab without any tabs and old controller doesn't disappear.
This is what I've done:
SwitchAppelegate
-- Header file --
#import <UIKit/UIKit.h>
#class SwitchClass;
#interface SwitchAppDelegate : NSObject <UIApplicationDelegate> {
SwitchClass *switchClass;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet SwitchClass *switchClass;
#property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
#property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel;
#property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;
- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;
#end
-- Implementation file --
#import "SwitchAppDelegate.h"
#implementation SwitchAppDelegate
#synthesize window=_window;
#synthesize managedObjectContext=__managedObjectContext;
#synthesize managedObjectModel=__managedObjectModel;
#synthesize persistentStoreCoordinator=__persistentStoreCoordinator;
#synthesize switchClass;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self.window addSubview:[switchClass view]];
[self.window makeKeyAndVisible];
return YES;
}
SwitchClass
-- Header file --
#import <UIKit/UIKit.h>
#class BlueClass;
#interface SwitchClass : UIViewController {
BlueClass *blueClass;
}
#property (nonatomic, retain) IBOutlet BlueClass *blueClass;
#end
-- Implementation file --
#import "SwitchClass.h"
#import "BlueClass.h"
#implementation SwitchClass
#synthesize blueClass;
-(void) viewDidLoad {
BlueClass *blue = [[BlueClass alloc] initWithNibName:#"BlueClass" bundle:nil];
self.blueClass = blue;
[self.view insertSubview:blue.view atIndex:0];
[blue release];
[super viewDidLoad];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)dealloc
{
[blueClass release];
[super dealloc];
}
BlueClass
-- Header file --
#class RedClass;
#interface BlueClass : UIViewController {
RedClass *redClass;
}
#property (nonatomic, retain) IBOutlet RedClass *redClass;
-(IBAction) switch: (id) sender;
#end
-- Implementation file --
#import "BlueClass.h"
#import "RedClass.h"
#implementation BlueClass
#synthesize redClass;
-(IBAction) switch: (id) sender {
RedClass *blue = [[RedClass alloc] initWithNibName:#"RedClass" bundle:nil];
self.redClass = blue;
// self.window.rootViewController = self.tabBarController;
[self.view addSubview:blue.view];
[blue release];
[super viewDidLoad];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)dealloc
{
[redClass release];
[super dealloc];
}
RedClass
-- Header file --
#import <UIKit/UIKit.h>
#interface RedClass : UITabBarController {
}
#end
-- Implementation file --
#import "RedClass.h"
#implementation RedClass
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
First thing is that in the appDelegate you are adding the view of SwitchClass. But SwitchClass is a UIViewController class and not UIView. so instead of that you should add your SwitchClass as a rootController like this:
self.window.rootViewController = self.switchClass;
If I were you I would just use a tab bar template provided by XCode. It will do it for you automatically.
I have started learning iphone apps development. However when I build and run the project, the simulator opens with new app icon. When I click on the new app icon ...nothing happens.
-->> simulator just sits there and doesn't load the app
Any help will be appreciated.
Marty
Actually it is not my code. I got it from the book I am studying from. Here it is:-
#import "basicViewController.h"
#implementation basicViewController
#synthesize txtName;
#synthesize lblMessage;
- (IBAction) doSomething;
{
NSString *msg =[[NSString alloc] initWithFormat:#"Hello, %#", txtName.text];
[lblMessage setText:msg];
[msg release];
}
- (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
//------------------------
#import <UIKit/UIKit.h>
#interface basicViewController : UIViewController {
IBOutlet UITextField *txtName;
IBOutlet UILabel *lblMessage;
}
#property (nonatomic, retain) IBOutlet UITextField *txtName;
#property (nonatomic, retain) IBOutlet UILabel *lblMessage;
- (IBAction) doSomething;
#end