Transparent UITableView on top of several UIViewController and OpenGLView (Cocos2D) - objective-c

Here is my code :
// View Controller with navigation bar
InAppPurchaseViewController *purchaseViewController = [[InAppPurchaseViewController alloc] init];
purchaseViewController.title = #"Magasin";
purchaseViewController.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(dismissViewController:)] autorelease];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:purchaseViewController] autorelease];
// Add `purchaseViewcontroller` TO container AND container ON openGLView
UIViewController *container = [[UIViewController alloc] init];
[container setView:[[CCDirector sharedDirector] openGLView]];
[container setModalTransitionStyle: UIModalTransitionStyleCoverVertical];
[container presentViewController:navController animated:YES completion:nil];
The UITableView is in purchaseViewController.
I was thinking of using [UIColor clearColor], BUT whatever I use it on I get a BLACK background on my UITableView. The cells get unselectable and unslidable (apart from the elements that are into the cells)
EDIT : The appdelegate
Here is the .h
#class AudioEngine;
#class RootViewController;
#class Score;
#interface AppDelegate : NSObject <UIApplicationDelegate, GameCenterManagerDelegate>
#property int CurrentPackage;
#property int CurrentScore;
#property int CurrentHighScore;
#property BOOL SoundShouldPlay;
#property BOOL PauseScreenUp;
#property(nonatomic, retain) AudioEngine *CustomAudioEngine;
#property(nonatomic, retain) GameCenterManager *CustomGameCenterManager;
#property(nonatomic, retain) UIWindow *window;
#property(nonatomic, readonly) RootViewController *ViewController;
#property(nonatomic, retain) NSString* CurrentLeaderBoard;
#property(nonatomic, retain) NSMutableArray *TenLastScoresArray;
+(AppDelegate *)get;
-(void)connectToGameCenter;
-(void)addScoreToLastScore:(Score*)score;
And the method did finish launching
-(void)applicationDidFinishLaunching:(UIApplication*)application
{
CC_DIRECTOR_INIT();
self.CurrentLeaderBoard = kLeaderboardID;
[[SKPaymentQueue defaultQueue] addTransactionObserver:[InAppPurchaseSingleton sharedHelper]];
[AudioEngine preloadBackgroundMusic];
[AudioEngine playBackgroundMusic:3];
self.SoundShouldPlay = YES;
[SceneManager goSplash];
}

Instead of presenting the view controller on container:
UIViewController *container = [[UIViewController alloc] init];
...
[container presentViewController:navController animated:YES completion:nil];
what should work is presenting it on the root view controller that the cocos2D template created for you. It is normally accessible through the app delegate:
UIViewController *rootViewController = (UIViewController*)[(YOURAPPDELEGATE*)[[UIApplication sharedApplication] delegate] viewController];
[rootViewController presentViewController:navController animated:YES completion:nil];
viewController is an ivar that the cocos2D default template add to the application delegate class. It is normally private, so you will need to define an accessor:
#property (nonatomic, readonly) RootViewController *viewController; //-- .h file
#synthesize viewController; //-- .m file
Hope this helps.
EDIT:
Based on what I have in my app delegate, I think you could try and instantiate the RootViewController like this:
CC_DIRECTOR_INIT
ViewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
ViewController.wantsFullScreenLayout = YES;
[ViewController setView:[[CCDirector sharedDirector] openGLView]];
...

Related

Impossible to presentViewController

I've created a new application view based.
Here some the main code:
// AppDelegate.h
#interface AppDelegate : UIResponder <UIApplicationDelegate>
{
UINavigationController *navigationController;
MIAPreferences *preferences;
}
#property (strong, nonatomic) UINavigationController *navigationController;
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) MIAPreferences *preferences;
// AppDelegate.m
#implementation AppDelegate
#synthesize window = _window;
#synthesize navigationController;
#synthesize preferences;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
// Override point for customization after application launch.
UIViewController *rootController = [[HomeViewController alloc] initWithNibName:nil bundle:nil];
navigationController = [[UINavigationController alloc]
initWithRootViewController:rootController];
navigationController.navigationBar.hidden = YES;
self.window = [[UIWindow alloc]
initWithFrame:[[UIScreen mainScreen] bounds]];
_window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
return YES;
}
// HomeViewController.m
-(IBAction)openLogin
{
LoginViewController *view = [[LoginViewController alloc] initWithNibName:nil bundle:nil];
// 1
[self.navigationController presentViewController:view animated:YES completion:nil];
// 2
[self.navigationController pushViewController:view animated:YES];
// 3
[self presentViewController:view animated:YES completion:nil];
}
All 3 options returns a EXC_BAD_ACCESS (code=2, address=....)
Can you please help me understand how to solve this?
UPDATE
The problem was due to a UIButton apparence set up during AddDelegate loading....but the first button was in the UIView I was going to load... that's why it crashed -.-"
It could either mean: (1) The pointer used to point to memory that was ok, but its chunk was deallocated or (2) The pointer is corrupt. You can try to use zombie mode, if you aren't already, to get more information. In XCode press the Command, option, and I keys and a screen should pop up. Selected the Run option in the left hand side, then Diagnostics, and under memory management enable zombie objects should be checked.
Check the value of view after initWithNibName:. init'ing with a nil nib name looks wrong to me, and you may be trying to push a nil view controller onto your navigation stack.

iphone changing the initial scene

In my iphone application I have two scenes, both of them are view controllers.
Normally initial scene is set to the first one. When user plays it passes to the second one.
At this point when the user closes the app and restarts it, if the user has already played, it should start with the second scene, so the initial scene should change for that user.
How can I do this?
And i dont use a navigation controller.
If you are using xibs, you set this up in the app delegates
applicationDidFinishLaunchingWithOptions.
Create a global BOOL and check it's value on applications launch, E.g:
.h
#class ViewController;
#class SecondViewController;
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) ViewController *viewController;
#property (strong, nonatomic) SecondViewController *SecondViewController;
.m
#import "ViewController.h"
#import "SecondViewController.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if (isSecondViewControllerBool == YES) {
self.SecondViewController = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
}else{
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
For storyboards:
In the first view controllers viewDidLoad.
- (void)viewDidLoad
{
if (isSecondViewControllerBool == YES) {
UIViewController *secondVC = [self.storyboard instantiateViewControllerWithIdentifier:#"mySecondViewController"];
[self presentViewController:secondVC animated:NO completion:nil];
}else{
//present normally
}
}
If you are using storyboards and have decided to use my xib solution, delete the storyboard from the project, and remove it here as well:

How to use custom UINavigationBar

I have subclass of UINavigationBar.
#interface MyNavigationBar : UINavigationBar
Made some changes and now want that my application NavigationController would use it:
_navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
[_window addSubview:[_navigationController view]];
[self.window makeKeyAndVisible];
I want that _navigationController would have MyNavigationBar
How this could be done ?
Thanks.
You have to create a xib with a UINavaigationController in it. You can then select the navigationBar in Interface Builder and change the class to your subclass of UINavigationBar.
Then to make this a little easier to instantiate I add a category to `UINavigationController like:
#interface UINavigationController (DSCNavigationController)
+ (UINavigationController *)dsc_navigationControllerWithRootViewController:(UIViewController *)rootViewController;
#end
#implementation UINavigationController (DSCNavigationController)
+ (UINavigationController *)dsc_navigationControllerWithRootViewController:(UIViewController *)rootViewController;
{
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:#"DSCNavigationController" owner:nil options:nil];
NSAssert(1 == [topLevelObjects count], #"DSCNavigationController should have one top level object");
UINavigationController *navigationController = [topLevelObjects objectAtIndex:0];
NSAssert([navigationController isKindOfClass:[UINavigationController class]], #"Should have a UINavigationController");
[navigationController pushViewController:rootViewController animated:NO];
return navigationController;
}
#end
At the top of the class that uses it makes sure to import the category in my case it looks like
#import "UINavigationController+DSCNavigationController"
Then using it looks something like
MyViewController *myViewController = [[MyViewController alloc] init];
UINavigationController *navigationController = [UINavigationController dsc_navigationControllerWithRootViewController:myViewController];
UINavigationController has a read-only property
#property(nonatomic, readonly) UINavigationBar *navigationBar
since it is read-only you have to subclass UINavigationBar and override this property or make it read-write.E.g. :
MyNaviagtionBar *myBar = [[MyNavigationBar alloc] init];
_navigationController.navigationBar = mybar;
Or subclassing:
MyNavigationController.h
#class MyNavigationBar;
#interface MyNavigationController : UINavigationController
#property(nonatomic, strong) MyNavigationBar *navigationBar;
#end
MyNavigationController.m
#implementation MyNavigationController
#synthesize navigationBar = _navigationBar;
#end
And then change
_navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
to
_navigationController = [[MyNavigationController alloc] initWithRootViewController:self.viewController];

Change size of View in UYLModalViewController

I create an modal View controller. And In I crate TableView And TextField
In vertical position all ok!
Verticlal
But in horizontal a can see all of this
How can I resize my view for it?
Here the code of call ModalView
-(IBAction)buttonTapped:(id)sender{
UYLModalViewController *modalVC = [[UYLModalViewController alloc] initWithNibName:#"UYLModalViewController" bundle:nil];
modalVC.delegate = self;
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:modalVC];
if (modalViewShowType==1)
{
nc.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentModalViewController:nc animated:YES];
}
else{
nc.modalPresentationStyle = UIModalPresentationFormSheet;
nc.view.bounds = CGRectMake(0, 0, 320, 480);
[self presentModalViewController:nc animated:YES];
//nc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
//nc.view.frame = CGRectMake(0, 0, 320, 480);//it's important to do this after presentModalViewController
//nc.view.center = self.view.center;
}
[modalVC release];
[nc release];
}
and here the declaration of controller for modalView
#protocol UYLModalViewControllerDelegate
-(void) buttonDonePassed :(NSArray *) variables;
#end
#interface UYLModalViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate>
{
id<UYLModalViewControllerDelegate> delegate;
//id<UITextFieldDelegate> textdelegate;
// id<UITextField> txt;
IBOutlet UITableView *tblView;
IBOutlet UITextField *textField;
NSMutableArray *cellsArray;
BOOL isAddedNewRow;
//UITextField *textField;
}
- (UITableViewCell *) getCellContentView:(NSString *)cellIdentifier :(NSInteger *)cellRow;
//-(void) clickToTextField:(id)sender;
#property (nonatomic, assign) id<UYLModalViewControllerDelegate> delegate;
#property (nonatomic, retain) IBOutlet UITableView *tblView;
#property (retain, nonatomic) IBOutlet UITextField *textField;
#end
As I can see in debug mode when the device in horizontal position it doesn't go to the tableview delegate methods =(
1) Where is defined the methode :
-(IBAction)buttonTapped:(id)sender;
I think that there is a problem with presenting modal a viewController over an
UISplitViewController...try to present it over an other ViewController to test
2) the UISplitViewController can create some problems if you use it not correctly
example: try to addSubView its view ( you can't push it )
3) Verify with the auoresizeMask of UYLModalViewController view

UIPopoverController Delegate Problem?

I have a UIPopover that I want to use either
-(BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController{
return NO;
}
or
-(void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController{}
on. Neither of them seem to work (and I'm sure once one is fixed, the other will be too since it's probably a problem with delegates). For delegates, here is what I have:
In optionsViewController.h, the view which is inside the popover:
#import <UIKit/UIKit.h>
#protocol OptionsViewControllerDelegate <NSObject>
-(void)didPick:(NSString *)string;
#end
id delegate;
#interface OptionsViewController : UIViewController <OptionsViewControllerDelegate>{
IBOutlet UIPickerView *picker;
NSMutableArray *list;
}
#property (nonatomic, copy) NSArray *passthroughViews;
#property(nonatomic,retain) NSMutableArray *list;
#property(nonatomic,assign) id<OptionsViewControllerDelegate> delegate;
#end
and in the .m:
#synthesize delegate;
and in the .h of the view where the popover appears:
#interface exampleViewController : UIViewController <OptionsViewControllerDelegate,UIPopoverControllerDelegate>{
UIPopoverController *popoverController;
OptionsViewController *optionsViewController;
}
and in the .m:
#synthesize popoverController;
#synthesize optionsViewController;
-(BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController{
return NO;
}
[popoverController release];
[optionsViewController release];
In the ViewDidLoad, I have:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
optionsViewController =[[OptionsViewController alloc]init];
optionsViewController.delegate = self;
popoverController = [[UIPopoverController alloc] initWithContentViewController:optionsViewController];
popoverController.popoverContentSize = CGSizeMake(320, 216);
}
To present the popover, I use:
-(IBAction)showDecadePopover{
[popoverController presentPopoverFromRect:CGRectMake(150, 50, 150, 50) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
}
I'm probably missing something really obvious (that's why I gave so much of my code). Thanks so much!
Luke
Yep, simple fix. After you init the popoverController you need to set the exampleViewController as the delegate of it.
[popoverController setDelegate:self];
PS: What is the id delegate; floating after your OptionsViewControllerDelegate protocol definition for? Synthesizing delegate, which you already do, is all you need to create storage for it.