PageViewController with Different xib (rather than different UIViewControllers) - uiviewcontroller

I am new to programming and am trying to make a PageViewController using xib's.
I have followed a tutorial found on SO which showed me how to make a PageViewController using different UIViewControllers in storyboard (I have pasted the code below). This works well, however, for my final app I would like to use a PageViewController in an xib (with multiple different xibs).
#import "IntroPages.h"
#implementation IntroPages
{
NSArray *myViewControllers;
}
-(void)viewDidLoad
{
[super viewDidLoad];
self.delegate = self;
self.dataSource = self;
UIViewController *p1 = [self.storyboard instantiateViewControllerWithIdentifier:#"1ID"];
UIViewController *p2 = [self.storyboard instantiateViewControllerWithIdentifier:#"2ID"];
UIViewController *p3 = [self.storyboard instantiateViewControllerWithIdentifier:#"3ID"];
UIViewController *p4 = [self.storyboard instantiateViewControllerWithIdentifier:#"4ID"];
myViewControllers = #[p1,p2,p3,p4];
[self setViewControllers:#[p1]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO completion:nil];
}
-(UIViewController *)viewControllerAtIndex:(NSUInteger)index
{
return myViewControllers[index];
}
-(UIViewController *)pageViewController:(UIPageViewController *)pageViewController
viewControllerBeforeViewController:(UIViewController *)viewController
{
NSUInteger currentIndex = [myViewControllers indexOfObject:viewController];
--currentIndex;
currentIndex = currentIndex % (myViewControllers.count);
return [myViewControllers objectAtIndex:currentIndex];
}
-(UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
NSUInteger currentIndex = [myViewControllers indexOfObject:viewController];
++currentIndex;
currentIndex = currentIndex % (myViewControllers.count);
return [myViewControllers objectAtIndex:currentIndex];
}
-(NSInteger)presentationCountForPageViewController: (UIPageViewController *)pageViewController {
return myViewControllers.count;
}
-(NSInteger)presentationIndexForPageViewController: (UIPageViewController *)pageViewController {
return 0;
}

Related

Google Maps iOS SDK mylocation button not showing

I enabled myLocation and myLocationButton,
but it not showing on my view.
And I try log _mapView.myLocation it's nil.
I need to showing myLocation dot and myLocationButton.
Have some one can help me, thanks!
//
// ViewController.m
//
#import "ViewController.h"
#import <CoreLocation/CoreLocation.h>
#import <GoogleMaps/GoogleMaps.h>
#import "Reachability.h"
#interface ViewController ()<GMSMapViewDelegate,CLLocationManagerDelegate>
{
CLLocationManager * locationManager;
CLLocation *currentLocations;
Reachability * udnReach;
};
#property (strong,nonatomic) GMSMapView * mapView;
#property (strong,nonatomic) NSDictionary * dic;
#property (nonatomic,strong) NSTimer * updatetimer;
#end
#implementation ViewController {
}
- (void)viewDidLoad {
locationManager =[[CLLocationManager alloc]init];
locationManager.delegate =self;
if ([locationManager respondsToSelector:#selector(requestAlwaysAuthorization)]) {
[locationManager requestAlwaysAuthorization];
}
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.activityType = CLActivityTypeAutomotiveNavigation;
[locationManager startUpdatingLocation];
_mapView.delegate = self;
_mapView.myLocationEnabled = YES;
_mapView.settings.myLocationButton = YES;
//Map
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:locationManager.location.coordinate.latitude
longitude:locationManager.location.coordinate.longitude
zoom:16];
_mapView= [GMSMapView mapWithFrame:CGRectZero camera:camera];
[[NSNotificationCenter defaultCenter]addObserver:self selector:#selector(networkStatusChanged:) name:kReachabilityChangedNotification object:nil];
udnReach=[Reachability reachabilityWithHostName:#"google.com"];
// udnReach = [Reachability reachabilityForInternetConnection];
[udnReach startNotifier];
[self updatebike];
self.view = self.mapView;
NSLog(#"User's location: %#", _mapView.myLocation);
// Do any additional setup after loading the view, typically from a nib.
[super viewDidLoad];
}
i find to show button and get userlocation
// Rather than setting -myLocationEnabled to YES directly,
// call this method:
- (void)enableMyLocation
{
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
if (status == kCLAuthorizationStatusNotDetermined)
[self requestLocationAuthorization];
else if (status == kCLAuthorizationStatusDenied || status == kCLAuthorizationStatusRestricted)
return; // we weren't allowed to show the user's location so don't enable
else
[self.view setMyLocationEnabled:YES];
}
// Ask the CLLocationManager for location authorization,
// and be sure to retain the manager somewhere on the class
- (void)requestLocationAuthorization
{
_locationAuthorizationManager = [[CLLocationManager alloc] init];
_locationAuthorizationManager.delegate = self;
[_locationAuthorizationManager requestAlwaysAuthorization];
}
// Handle the authorization callback. This is usually
// called on a background thread so go back to main.
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
if (status != kCLAuthorizationStatusNotDetermined) {
[self performSelectorOnMainThread:#selector(enableMyLocation) withObject:nil waitUntilDone:[NSThread isMainThread]];
_locationAuthorizationManager.delegate = nil;
_locationAuthorizationManager = nil;
}
}

Alert View directs to an empty view controller without buttons

I'm trying to make an alert view so that upon selecting "Yes" (one of the buttons in AlertView), the user is directed to a new view controller with a button which I made via Storyboard. My code for the IBAction is as follows:
- (IBAction)alertButton:(UIButton *)sender
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Welcome Back to SymTrack!" message:#"Did you have reoccuring symptoms?" delegate:self cancelButtonTitle:#"No" otherButtonTitles:#"Yes", nil];
[alert show];
}
This is the code for the clickedButtonAtIndex which gives me the empty view controller without the button:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1)
{
UpdateViewController *updateVC = [[UpdateViewController alloc] init];
[self presentViewController:updateVC animated:YES completion:nil];
}
}
I've also tried these other codes for clickedButtonAtIndex but I got NSException for all of them:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1)
{
UpdateViewController *updateVC = [self.storyboard instantiateViewControllerWithIdentifier:#"UpdateViewController"];
[self presentViewController:updateVC animated:YES completion:nil];
}
}
or
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1)
{
UpdateViewController *updateVC = [self.storyboard instantiateViewControllerWithIdentifier:#"UpdateViewController"];
UINavigationController *alertNC = [[UINavigationController alloc] initWithRootViewController:updateVC];
[self presentViewController:updateVC animated:YES completion:nil];
}
}
note: all this code is within the view controller with the button that upon clicking brings the alert view up.
Thanks in advance!

Cannot load the Google Maps view in iOS

I'm trying to load google maps view in iOS following the guide here
I created a new viewController for the map view called iptechMapViewController.h , iptechMapViewController.m and iptechMapViewController.xib
Here is the code in iptechMapViewController.m :
#import "iptechMapViewController.h"
#import <GoogleMaps/GoogleMaps.h>
#interface iptechMapViewController ()
{
GMSMapView *mapView_;
}
#end
#implementation iptechMapViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)loadView
{
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.8683
longitude:151.2086
zoom:6];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
self.view = mapView_;
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(-33.8683, 151.2086);
marker.title = #"Sydney";
marker.snippet = #"Australia";
marker.map = mapView_;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Then in another view controller named iptechFlipsideViewController.m I'm trying to show the iptechMapViewController as follows:
- (IBAction)showMap:(id)sender
{
iptechMapViewController *controller = [[iptechMapViewController alloc] initWithNibName:#"iptechMapViewController" bundle:nil];
[self.view addSubview:controller.view];
}
But after clicking the showMap button which is connected to the IBAction showMap, and after iOS asks permission to access my location alert appears and I touch OK, after that nothing shows up and in the console I get the following error"
Failed to make complete framebuffer object 8cd6
Thanks
Passing CGRectZero to mapWithFrame only works if the map view is the root view controller's root view - in which case it is resized to fit the screen. In your case since the map is a subview, you will need to specify a size when creating the map view.

NSArray from MySQL to NSTableView

First of all, I'm new to objective-c programming so I've probably made some mistakes in my code.
Here's what I've done : I've created a php file with some xml to get values from my MySQL database. Everything goes into a NSArray in objective-C. If I look at the log, everything works fine because it shows my arrays with every MySQL rows and columns like this:
2012-04-02 08:20:14.822 POS[64632:707] (
{
CPU = 0;
TPS = "(null)";
TVQ = "(null)";
consigne = 0;
coutantQuantiteRecue = 0;
description = "";
nom = "";
prixProduit = 0;
quantiteRecue = 0;
stock = 0;
},
{
CPU = 768;
TPS = "(null)";
TVQ = "(null)";
consigne = 0;
coutantQuantiteRecue = 0;
description = "";
nom = hhh;
prixProduit = 0;
quantiteRecue = 0;
stock = 0;
},
2012-04-02 08:20:14.836 POS[64632:707] The number of rows is:2
The problem is that the only thing I get in my TableView is { in each cell like this:
Here's my .h :
#interface InventoryManagement : NSObject<NSApplicationDelegate, NSTableViewDataSource>
{
IBOutlet NSTableView* inventoryTable;
NSArray* m_items;
}
-(int)numberOfRowsInTableView:(NSTableView *)inventoryTable;
-(id)tableView:(NSTableView *)inventoryTable objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)rowIndex;
-(void)dealloc;
#property (retain) NSArray* m_items;
#end
And here's my .m file :
#implementation InventoryManagement
#synthesize m_items;
-(id)init
{
[super init];
NSInteger index = 0;
NSString *urlString = [NSString stringWithFormat:#"http://localhost:8888/php/getProducts.php?index=%d&", index];
m_items = [NSArray arrayWithContentsOfURL:[NSURL URLWithString: urlString]];
NSLog(#"%#", [m_items description]);
[m_items retain];
[inventoryTable reloadData];
return self;
}
-(int)numberOfRowsInTableView:(NSTableView *)inventoryTable
{
NSLog(#"The number of rows in fullResult is:%i", [m_items count]);
return [m_items count];
}
-(id)tableView:(NSTableView *)inventoryTable objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)rowIndex
{
return [m_items objectAtIndex:rowIndex];
}
-(void)dealloc
{
[m_items release];
[super dealloc];
}
#end
My object is well-connected to dataSource and delegate of my TableView. I want those cells to be filled by my database values.
Take a look at Cocoa Bindings for future works. They are great.
Regarding your question: the problem is in the method
-(id)tableView:(NSTableView *)inventoryTable objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)rowIndex
{
return [m_items objectAtIndex:rowIndex];
}
You are returning the whole object, that is:
{
CPU = 768;
TPS = "(null)";
TVQ = "(null)";
consigne = 0;
coutantQuantiteRecue = 0;
description = "";
nom = hhh;
prixProduit = 0;
quantiteRecue = 0;
stock = 0; }
which is a string.
You have to check the tableColumn variable and return only the right information: e.g. quantiteRecue, CPU, etc..
The best way to do this is to create a Model class in ObjectiveC which wraps a row of your db. Then your m_items array will contains your Model class, and you can return the right property without parsing every time the string...

How to enable cc touch events when i add CCLayer to UIViewController

here is my code:
#import "VirusViewController.h"
#import "MainGame.h"
#import "cocos2d.h"
#implementation VirusViewController
#synthesize window;
- (void)loadView {
// Initialization code
CC_DIRECTOR_INIT();
CCDirector *director = [CCDirector sharedDirector];
//landscape
[director setDeviceOrientation:kCCDeviceOrientationPortrait];
[director setDisplayFPS:YES];
//turn on multi-touch
EAGLView *cocosView = [director openGLView];
[cocosView setMultipleTouchEnabled:YES];
self.view = cocosView;
//default texture formats...
[CCTexture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA8888];
[[CCDirector sharedDirector] runWithScene:[MainGame scene]];
}
-(void)viewDidLoad
{
UIButton *nextButton = [[UIButton alloc] initWithFrame:CGRectMake(40, 40, 64, 64)];
[nextButton setImage:[UIImage imageNamed:#"homeButton.png"] forState:UIControlStateNormal];
[nextButton addTarget:self action:#selector(goBack) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:nextButton];
[nextButton release];
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[[CCDirector sharedDirector] purgeCachedData];
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[[CCDirector sharedDirector] release];
[window release];
[super dealloc];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
return YES;
}
-(void)goBack
{
[self.navigationController popViewControllerAnimated:YES];
}
nextButton is not receiving touch events when i init the CC_Director_INIT();
also - (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
is not working inside a subview of MainGame.h
in other words... I can't receive any touch events
Try giving your layer these methods
- (void)onEnter
{
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:NO];
[super onEnter];
}
- (void)onExit
{
[[CCTouchDispatcher sharedDispatcher] removeDelegate:self];
[super onExit];
}
sharedDispatcher is deprecated - you should use this instead:
[[CCDirector sharedDirector] touchDispatcher]