I need some help.
I have an app that is based on UITabBarController. It has 4 tabs. In the fourth tab, the user can select a picture from the library, or on iphone, take a picture. When an image is selected (or a photo is taken), after the picker is dismissed, the image is not shown. I am wrecking my head over it...help is much appreciated.
Here's the relevant code from the fourth view controller.
imageViewController.h:
#interface ImagesViewController : UIViewController <UINavigationControllerDelegate,
UIImagePickerControllerDelegate> {
IBOutlet UIImageView *ivImage;
}
#property (nonatomic, retain) IBOutlet UIImageView *myImage;
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error
contextInfo:(void *)contextInfo;
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker;
#end
imageViewController.m:
#synthesize myImage = ivImage;
-(void) imagePickerController: (UIImagePickerController *) picker
didFinishPickingMediaWithInfo:(NSDictionary *) imageInfo {
[picker dismissModalViewControllerAnimated:YES];
[picker release];
picker = nil;
UIImage *image = [imageInfo objectForKey:UIImagePickerControllerOriginalImage];
[[self myImage] image];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker.parentViewController dismissModalViewControllerAnimated:YES];
[picker release];
picker = nil;
}
- (void)pickPicture {
UIImagePickerController *picker = nil;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[picker setShowsCameraControls:YES];
picker.delegate = self;
picker.allowsEditing = NO;
self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:picker animated:YES];
}
}
try [self.tabbarcontroller presentModalViewController:picker animated:YES];
Related
In my effort to save a ScrollingBackground object I've subclassed the CCSprites to conform to NSCoding. The ScrollingBackground doesn't display. Please see the relevant code below. I'm not really sure whats wrong. Please help.
ScrollingBackground.h:
(CCBackgroundSprite's interface)
#interface CCBackgroundSprite: NSObject <NSCoding>
#property (nonatomic, assign) float xValue;
#property (nonatomic, assign) float yValue;
#property (nonatomic, retain) NSString* backgroundStringName;
#end
ScrollingBackground.m:
(CCBackgroundSprite's implementation)
#implementation CCBackgroundSprite
-(id)init
{
if((self = [super init])){
}
return self;
}
-(id) initWithCoder:(NSCoder *) aDecoder {
self = [super init];
if(self != nil) {
self.xValue = [aDecoder decodeFloatForKey:#"xValue"];
self.yValue = [aDecoder decodeFloatForKey:#"yValue"];
self.backgroundStringName = [aDecoder decodeObjectForKey:#"backgroundStringName"];
}
return self;
}
-(void) encodeWithCoder:(NSCoder *)aCoder {
[aCoder encodeFloat:self.xValue forKey:#"xValue"];
[aCoder encodeFloat:self.yValue forKey:#"yValue"];
[aCoder encodeObject:self.backgroundStringName forKey:#"backgroundStringName"];
}
#end
Setting CCBackgroundSprite's instances for the CCSprite properties:
-(void)spriteProperties {
background1 = [[CCBackgroundSprite alloc] init];
[background1 setXValue:bg.position.x];
[background1 setYValue:bg.position.y];
[background1 setBackgroundStringName:#"bg"];
background2 = [[CCBackgroundSprite alloc] init];
[background2 setXValue:bgSwap.position.x];
[background2 setYValue:bgSwap.position.y];
[background2 setBackgroundStringName:#"bgSwap"];
background3 = [[CCBackgroundSprite alloc] init];
[background3 setXValue:bgSwap2.position.x];
[background3 setYValue:bgSwap2.position.y];
[background3 setBackgroundStringName:#"bgSwap2"];
}
encoding/decoding of other non-Sprite related properties of the ScrollingBackground:
-(void) encodeWithCoder:(NSCoder *)aCoder {
[aCoder encodeInt:self.backgroundCount forKey:#"backgroundCount"];
[aCoder encodeInt:self.backgroundRepeatCount forKey:#"backgroundRepeatCount"];
[aCoder encodeFloat:self.scrollSpeed forKey:#"scrollSpeed"];
[aCoder encodeObject:self.backgroundArray forKey:#"backgroundArray"];
[aCoder encodeObject:self.changeArray forKey:#"changeArray"];
.
.
.
}
-(id) initWithCoder:(NSCoder *) aDecoder {
self = [super init];
if(self != nil) {
self.backgroundCount = [aDecoder decodeIntForKey:#"backgroundCount"];
self.backgroundRepeatCount = [aDecoder decodeIntForKey:#"backgroundRepeatCount"];
self.scrollSpeed = [aDecoder decodeFloatForKey:#"scrollSpeed"];
self.backgroundArray = [aDecoder decodeObjectForKey:#"backgroundArray"];
self.changeArray = [aDecoder decodeObjectForKey:#"changeArray"];
.
.
.
}
}
Saving and loading of ScrollingBackground object:
- (void)saveBackgroundObject:(ScrollingBackground *)object key:(NSString *)key {
[self spriteProperties];
NSData *encodedObject = [NSKeyedArchiver archivedDataWithRootObject:object];
NSString *dataToString = [NSString stringWithFormat:#"%#", encodedObject];
CCLOG(#"encodedObject = %# \n", dataToString);
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:encodedObject forKey:key];
[defaults synchronize];
}
-(ScrollingBackground *)loadBackgroundWithKey:(NSString *)key {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSData *encodedObject = [defaults objectForKey:key];
NSString *dataToString = [NSString stringWithFormat:#"%#", encodedObject];
CCLOG(#"encodedObject = %# \n", dataToString);
ScrollingBackground *object = [NSKeyedUnarchiver unarchiveObjectWithData:encodedObject];
return object;
}
UPDATED:
I have made the following changes the spriteProperties method:
-(void)spriteProperties {
background1 = [[CCBackgroundSprite alloc] init];
[background1 setXValue:bg.position.x];
[background1 setYValue:bg.position.y];
[background1 setBackgroundImageName:bg.displayFrame.textureFilename];
[self addChild:background1];
background2 = [[CCBackgroundSprite alloc] init];
[background2 setXValue:bgSwap.position.x];
[background2 setYValue:bgSwap.position.y];
[background2 setBackgroundImageName:bgSwap.displayFrame.textureFilename];
[self addChild:background2];
background3 = [[CCBackgroundSprite alloc] init];
[background3 setXValue:bgSwap2.position.x];
[background3 setYValue:bgSwap2.position.y];
[background3 setBackgroundImageName:bgSwap2.displayFrame.textureFilename];
[self addChild:background3];
}
The main reason I am using displayFrame.textureFilename above is because I'm reusing the sprites along the way.
Also to setup of the background images I did:
-(void)startingSprites //change later to setupInitialBackground
{
CGSize s = [[CCDirector sharedDirector] winSize];
bg = [CCSprite spriteWithSpriteFrameName:#"bgImage1.png"];
bg.position = ccp(s.width/2, s.height/2);
[currentBackgroundBatchNode addChild:bg];
swapbg = [CCSprite spriteWithSpriteFrameName:#"bgImage2.png"];
swapbg.position = ccp(s.width/2, 3*s.height/2 -1.0);
[currentBackgroundBatchNode addChild: swapbg];
swapbg2 = [CCSprite spriteWithSpriteFrameName:#"bgImage3.png"];
swapbg2.position = ccp(s.width/2, 5*s.height/2 - 2.0);
[currentBackgroundBatchNode addChild: swapbg2];
CCLOG(#"bg background is %#", bg.displayFrame.textureFilename);
CCLOG(#"bgSwap background is %#", swapbg.displayFrame.textureFilename);
CCLOG(#"bgSwap2 background is %#", swapbg2.displayFrame.textureFilename);
}
I've just realized a few things:
the CCLOG's in startingSprites are null
I reuse the currentBackgroundBatchNode (which is a CCSpriteBatchNode) along the way, meaning that I have to encode/decode it. How do I subclass it and with what properties? Not too sure how it'll work out.
I have read a number of your posts, also related to this. I would recommend that instead of trying to subclass several cocos2d classes to conform to NSCoding you should use a simpler work around. I believe your background has it's own layer, so why don't you rather save various background parameters and create another init for your background to handle cases for reloading the background state.
You say you've subclassed CCSprite, but you actually subclassed NSObject. Try:
#interface CCBackgroundSprite: CCSprite <NSCoding>
...
here is the situation:
I have a "UITableViewController" which loads objects with RestKits "RKFetchedResultsTableController". After clicking on a cell I switch to a detail UITableViewController also driven by a "RKFetchedResultsTableController" which gives me a corresponding answer text for the selected object.
The problem is now, if I go back to the first "UITableViewController" and select another object in the table the old answer text from the previous selected object is in the detail table. If I use the "pullToRefresh" function the table gets refreshed and the correct answer is loading.
Why is the old answer from the previous object still in the tableView and not the correct answer for the new selected Object even if I tell [tableController loadTable] in the viewWillAppear method.
AppDelegate:
#
interface AppDelegate ()
#property (nonatomic, strong, readwrite) RKObjectManager *objectManager;
#property (nonatomic, strong, readwrite) RKManagedObjectStore *objectStore;
#end;
#implementation AppDelegate
#synthesize window = _window, isAuthenticated;
#synthesize objectManager;
#synthesize objectStore;
- (void)initializeRestKit
{
//self.objectManager = [RKObjectManager managerWithBaseURLString:#"http://falling-ocean-1302.herokuapp.com"];
self.objectManager = [RKObjectManager managerWithBaseURLString:#"http://falling-ocean-1302.herokuapp.com"];
self.objectManager.serializationMIMEType = RKMIMETypeJSON;
self.objectManager.acceptMIMEType = RKMIMETypeJSON;
self.objectStore = [RKManagedObjectStore objectStoreWithStoreFilename:#"MMmtvzme.sqlite"];
self.objectManager.objectStore = self.objectStore;
self.objectManager.mappingProvider = [MMMappingProvider mappingProviderWithObjectStore:self.objectStore];
self.objectManager.client.cachePolicy = RKRequestCachePolicyNone;
RKLogConfigureByName("RestKit", RKLogLevelTrace);
RKLogConfigureByName("RestKit/Network", RKLogLevelTrace);
RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace);
RKLogConfigureByName("RestKit/Network/Queue", RKLogLevelTrace);
// Enable automatic network activity indicator management
objectManager.client.requestQueue.showsNetworkActivityIndicatorWhenBusy = YES;
[objectManager.router routeClass:[MMRequest class] toResourcePath:#"/requests" forMethod:RKRequestMethodPOST];
[objectManager.router routeClass:[MMRequest class] toResourcePath:#"/requests" forMethod:RKRequestMethodDELETE];
[objectManager.router routeClass:[MMAnswer class] toResourcePath:#"/requests/:request_id/answers" forMethod:RKRequestMethodPOST];
}
Ok this is the code from the first UITableViewController
#interface MMMyRequestList ()
#property (nonatomic, strong) RKFetchedResultsTableController *tableController;
#end
#implementation MMMyRequestList
#synthesize tableController;
- (void)viewDidLoad
{
[super viewDidLoad];
[self configureRKTableController];
[self configureCellMapping];
[self useCustomNib];
}
- (void)configureRKTableController{
self.tableController = [[RKObjectManager sharedManager] fetchedResultsTableControllerForTableViewController:self];
self.tableController.autoRefreshFromNetwork = YES;
self.tableController.pullToRefreshEnabled = YES;
self.tableController.resourcePath = #"/requests";
self.tableController.variableHeightRows = YES;
NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:#"request_id" ascending:NO];
self.tableController.sortDescriptors = [NSArray arrayWithObject:descriptor];
tableController.canEditRows = YES;
}
- (void)configureCellMapping{
RKTableViewCellMapping *cellMapping = [RKTableViewCellMapping cellMapping];
cellMapping.cellClassName = #"MMRequestCell";
cellMapping.reuseIdentifier = #"MMRequest";
cellMapping.rowHeight = 100.0;
[cellMapping mapKeyPath:#"title" toAttribute:#"requestLabel.text"];
[cellMapping mapKeyPath:#"user.first_name" toAttribute:#"userLabel.text"];
cellMapping.onSelectCellForObjectAtIndexPath = ^(UITableViewCell *cell, id object, NSIndexPath* indexPath)
{
MMMyRequestListAnswer * uic = [self.storyboard instantiateViewControllerWithIdentifier:#"MMMyRequestListAnswer"];
MMRequest *request = [self.tableController objectForRowAtIndexPath:indexPath];
if ([uic respondsToSelector:#selector(setRequest:)]) {
[uic setRequest:request];
}
[self.navigationController pushViewController:uic animated:YES];
};
[tableController mapObjectsWithClass:[MMRequest class] toTableCellsWithMapping:cellMapping];
}
- (void)useCustomNib{
[self.tableView registerNib:[UINib nibWithNibName:#"MMRequestCell" bundle:nil] forCellReuseIdentifier:#"MMRequest"];
}
- (void)objectLoader:(RKObjectLoader*)objectLoader didFailWithError:(NSError*)error {
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:#"Error"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
NSLog(#"Hit error: %#", error);
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
/**
Load the table view!
*/
[tableController loadTable];
}
After clicking on a cell the Detail UIViewController come into action
interface MMMyRequestListAnswer ()
#property (nonatomic, strong) RKFetchedResultsTableController *tableController;
#end
#implementation MMMyRequestListAnswer
#synthesize tableHeaderView, requestTextLabel;
#synthesize request;
#synthesize tableController;
- (void)viewDidLoad
{
[super viewDidLoad];
[self configureRKTableController];
[self configureCellMapping];
[self useCustomNib];
}
- (void)configureRKTableController{
self.tableController = [[RKObjectManager sharedManager] fetchedResultsTableControllerForTableViewController:self];
self.tableController.autoRefreshFromNetwork = YES;
self.tableController.pullToRefreshEnabled = YES;
self.tableController.resourcePath = [NSString stringWithFormat:#"/requests/%i/answers", [self.request.request_id intValue]];
self.tableController.variableHeightRows = YES;
NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:#"answer_id" ascending:NO];
self.tableController.sortDescriptors = [NSArray arrayWithObject:descriptor];
}
- (void)configureCellMapping{
RKTableViewCellMapping *cellMapping = [RKTableViewCellMapping cellMapping];
cellMapping.cellClassName = #"MMRequestAnswerCell";
cellMapping.reuseIdentifier = #"MMAnswer";
cellMapping.rowHeight = 80.0;
[cellMapping mapKeyPath:#"text" toAttribute:#"answerLabel.text"];
[cellMapping mapKeyPath:#"user.first_name" toAttribute:#"userLabel.text"];
[tableController mapObjectsWithClass:[MMAnswer class] toTableCellsWithMapping:cellMapping];
}
- (void)useCustomNib{
[self.tableView registerNib:[UINib nibWithNibName:#"MMRequestAnswerCell" bundle:nil] forCellReuseIdentifier:#"MMAnswer"];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
/**
Load the table view!
*/
[tableController loadTable];
}
The Object Mapping is handled in this Class:
#implementation MMMappingProvider
#synthesize objectStore;
+ (id)mappingProviderWithObjectStore:(RKManagedObjectStore *)objectStore {
return [[self alloc] initWithObjectStore:objectStore];
}
- (id)initWithObjectStore:(RKManagedObjectStore *)theObjectStore {
self = [super init];
if (self) {
self.objectStore = theObjectStore;
[self setObjectMapping:[self requestObjectMapping] forResourcePathPattern:#"/requests" withFetchRequestBlock:^NSFetchRequest *(NSString *resourcePath) {
NSFetchRequest *fetchRequest = [MMRequest fetchRequest];
return fetchRequest;
}];
[self setObjectMapping:[self answerObjectMapping] forResourcePathPattern:#"/requests/:request_id/answers" withFetchRequestBlock:^NSFetchRequest *(NSString *resourcePath) {
NSFetchRequest *fetchRequest = [MMAnswer fetchRequest];
fetchRequest.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:#"answer_id" ascending:YES]];
return fetchRequest;
}];
[self setSerializationMapping:[self.requestObjectMapping inverseMapping] forClass:[MMRequest class]];
[self setSerializationMapping:[self.answerObjectMapping inverseMapping] forClass:[MMAnswer class]];
[self setSerializationMapping:[self.userObjectMapping inverseMapping] forClass:[MMUser class]];
}
return self;
}
- (RKManagedObjectMapping *)userObjectMapping {
RKManagedObjectMapping *mapping = [RKManagedObjectMapping mappingForEntityWithName:#"MMUser" inManagedObjectStore:self.objectStore];
mapping.primaryKeyAttribute = #"user_id";
[mapping mapAttributes:#"first_name", nil];
[mapping mapKeyPathsToAttributes:
#"id", #"user_id",
nil];
return mapping;
}
- (RKManagedObjectMapping *)answerObjectMapping {
RKManagedObjectMapping *mapping = [RKManagedObjectMapping mappingForEntityWithName:#"MMAnswer" inManagedObjectStore:self.objectStore];
mapping.primaryKeyAttribute = #"answer_id";
[mapping mapAttributes:#"text",#"request_id",#"user_id", nil];
[mapping mapKeyPathsToAttributes:
#"id", #"answer_id",
nil];
[mapping mapKeyPath:#"user" toRelationship:#"user" withMapping:[self userObjectMapping]];
[mapping mapKeyPath:#"request" toRelationship:#"request" withMapping:[self requestObjectMapping]];
return mapping;
}
- (RKManagedObjectMapping *)requestObjectMapping {
RKManagedObjectMapping *mapping = [RKManagedObjectMapping mappingForEntityWithName:#"MMRequest" inManagedObjectStore:self.objectStore];
mapping.primaryKeyAttribute = #"request_id";
[mapping mapAttributes:#"title",#"user_id", nil];
[mapping mapKeyPathsToAttributes:
#"id", #"request_id",
nil];
[mapping mapKeyPath:#"user" toRelationship:#"user" withMapping:[self userObjectMapping]];
return mapping;
}
OK Figured it out!!! Some digging revealed that I was loading my UITableviewcontroller BEFORE the mapping provider.
The fix was, to take [self initialiserestkit] method in - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
and put it before any of the code in this method (i.e. make [self initialiserestkit] the first line of the didfinishlaunchingwithoptions method.
Issue solved. Now the tableview is loaded AFTER the mappings so everything works as it should.
Hi Im trying to change the tabcontroller flow, so when a user is not loged in just take him to the login view instead the settings one. My controller extends TabBarController and I set the delegate as
self.tabBarController.delegate=self;
My Code is:
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
if (login) {
LoginViewController *loginViewController = [[LoginViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:loginViewController];
[tabBarController presentViewController:loginViewController animated:YES completion:nil];
return NO;
} else {
return YES;
}
I never manage to do the navigation it gives an excetion :
ion 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller <UITabBarController: 0x6a72220>.
I also tried to show the login in as a modal but it only shows a black screen:
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
if (YES) {
LoginViewController *loginViewController = [[LoginViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:loginViewController];
[tabBarController presentModalViewController:navController animated:YES];
return NO;
} else {
return YES;
}
}
Can anybody help Me!!!! please!!!!
Well I manage to fix the black modal screen (still cant d a segue that is not modal).
The problem was that as I am using storyboard I have to load the view from story board as follows.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *navController = [storyboard instantiateViewControllerWithIdentifier:#"login"];
[navController setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentModalViewController:navController animated:YES];
That made the trick :)
TabBar will be about 2 question. I am using a combination of a TabBar and NavigationController. As the following link.
http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/CombiningViewControllers/CombiningViewControllers.html
Question 1:
I would like to appear before a TabBar to another ViewController. Several checks are here to do. (For example, Facebook login) If the prerequisites are met, tabbar will be visible. How do I do?
Question 2:
TabBar screen icon that appears in the middle of the first TabBar want it to be. The following code sequence also affects the order of TabBarItem.
self.tabBarController.viewControllers = [NSArray arrayWithObjects: viewController1, viewController2, nil];
Thank you.
Okan Sahin
For those who have the same problem:
I'm using Xcode 4.2. I have created Tabbed App.
Answer 1:
For loading screen,
I created a new ViewController.
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *viewControllerLoading = [[LoadingViewController alloc] initWithNibName:#"LoadingViewController" bundle:nil];
self.window.rootViewController = viewControllerLoading;
[self.window makeKeyAndVisible];
return YES;
}
LoadingViewController.h
#interface LoadingViewController : UIViewController <UITabBarControllerDelegate>
#property (strong, nonatomic) UITabBarController *tabBarController;
#end
LoadingViewController.m
UIViewController *viewControllerFriends = [[FriendsViewController alloc] initWithNibName:#"FriendsViewController" bundle:nil];
UINavigationController* navController1 = [[UINavigationController alloc]
initWithRootViewController:viewControllerFriends];
UIViewController *viewConrollerMessages = [[MessagesViewController alloc] initWithNibName:#"MessagesViewController" bundle:nil];
UINavigationController* navController2 = [[UINavigationController alloc]
initWithRootViewController:viewConrollerMessages];
UIViewController *viewControllerWorld = [[WorldViewController alloc] initWithNibName:#"WorldViewController" bundle:nil];
UINavigationController* navController3 = [[UINavigationController alloc]
initWithRootViewController:viewControllerWorld];
UIViewController *viewControllerCheckIn = [[CheckInViewController alloc] initWithNibName:#"CheckinViewController" bundle:nil];
UINavigationController* navController4 = [[UINavigationController alloc]
initWithRootViewController:viewControllerCheckIn];
UIViewController *viewControllerProfile = [[ProfileViewController alloc] initWithNibName:#"ProfileViewController" bundle:nil];
UINavigationController* navController5 = [[UINavigationController alloc]
initWithRootViewController:viewControllerProfile];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navController1, navController2, navController3, navController4, navController5, nil];
[self.view addSubview:self.tabBarController.view];
Answer 2:
self.tabBarController.selectedIndex = 2;
Best regards
Okan Sahin
I tried to include a custom button programmatically inside a UIView which is a subview of UITabBarController.
The button is displays fine but when I click it, it crashes without an error message. Its strange that sometimes it does inconsistently:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString playButton]: unrecognized selector sent to instance 0x632cd10'
I even tried removing any code in my play button method, i tried changing the name playButton to playAction, I also tried add the button directly to "self" not to aboutView but the result is still the same.
My guess is it got something to do with the tabBar having a UIView as a subview with a button on it. I don't know.
Here's a code snippet of how i built the tabBar in my appDelegate method
// About Tab
aboutViewC = [[[AboutViewController alloc] init] autorelease];
aboutNavC = [[[UIViewController alloc] init] autorelease];
aboutNavC.title = #"About";
aboutNavC.view = aboutViewC.view;
// Lessons Tab
lessonsViewC = [[[LevelViewController alloc] init] autorelease];
lessonsViewC.title = #"Levels";
lessonsNavC = [[[UINavigationController alloc] initWithRootViewController:lessonsViewC] autorelease];
lessonsNavC.title = #"Lessons";
lessonsNavC.viewControllers = [NSArray arrayWithObjects:lessonsViewC, nil];
tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects:aboutNavC, lessonsNavC, nil];
and heres the code for implementing the AboutViewController class
AboutViewController.h
#import
#interface AboutViewController : UIViewController {
UIButton *playSoundButton;
UIView *aboutView;
}
- (void)playButton;
#end
AboutViewController.m
#import "AboutViewController.h"
#implementation AboutViewController
- (void)dealloc {
[playSoundButton release];
[aboutView release];
[super dealloc];
}
- (void)viewDidLoad {
aboutView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[playSoundButton = [UIButton buttonWithType:UIButtonTypeCustom] retain];
image = [UIImage imageNamed:#"bt_play.png"];
[playSoundButton setImage:image forState:UIControlStateNormal];
[playSoundButton addTarget:self action:#selector(playButton) forControlEvents:UIControlEventTouchUpInside];
playSoundButton.frame = CGRectMake(0, 350, 40, 40);
[aboutView addSubview:playSoundButton];
stopSoundButton.hidden = YES;
playSoundButton.hidden = NO;
[self.view addSubview:aboutView];
[super viewDidLoad];
}
- (void)playButton
{
NSLog(#"playAction method");
}
#end
Thanks in advance!
[playSoundButton = [UIButton buttonWithType:UIButtonTypeCustom] retain]; should read playSoundButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
(i.e. move the first [ further right to UIButton)
Thanks tob for the feedback, i actually know how to implement retain statement, it was a typo i didn't notice. surprisingly, that is not the problem and the code run's fine now leaving the typo unchanged.
The real problem was in my appDelegate method.
Instead of
// About Tab
aboutViewC = [[[AboutViewController alloc] init] autorelease];
aboutNavC = [[[UIViewController alloc] init] autorelease];
aboutNavC.title = #"About";
aboutNavC.view = aboutViewC.view;
// Lessons Tab
lessonsViewC = [[[LevelViewController alloc] init] autorelease];
lessonsViewC.title = #"Levels";
lessonsNavC = [[[UINavigationController alloc] initWithRootViewController:lessonsViewC] autorelease];
lessonsNavC.title = #"Lessons";
lessonsNavC.viewControllers = [NSArray arrayWithObjects:lessonsViewC, nil];
tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects:aboutNavC, lessonsNavC, nil];
should be
// About Tab
aboutViewC = [[[AboutViewController alloc] init] autorelease];
aboutViewC.title = #"About";
// Lessons Tab
lessonsViewC = [[[LevelViewController alloc] init] autorelease];
lessonsViewC.title = #"Levels";
lessonsNavC = [[[UINavigationController alloc] initWithRootViewController:lessonsViewC] autorelease];
lessonsNavC.title = #"Lessons";
lessonsNavC.viewControllers = [NSArray arrayWithObjects:lessonsViewC, nil];
tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects:aboutViewC, lessonsNavC, nil];