Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-26-2009, 12:35 PM   #1 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 196
Default UInavigation + tabbar.. help

Hi, i read in this forum in other tread over this issue but not find the answer rigth.. so.. any can help me?

i have a application what handle a tab bar whit 5 buttons and one button=1view, this works fine.. this views have a data array to input to tableview.. this works fine.. but the problem is when i touch a row in tableview, this action will send me to other view whit data detail.. and this not happend. this the code.

delegate.h
#import <UIKit/UIKit.h>

@class negociosViewController;

@interface iPublicarAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UITabBarController *tabBarController;
negociosViewController *viewController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) negociosViewController *viewController;

@end

---------------

delegate.m
#import "delegateAppDelegate.h"
#import "categoriasViewController.h"
#import "negociosViewController.h"
#import "sitiosViewController.h"
#import "favoritosViewController.h"
#import "randomViewController.h"

@implementation delegateAppDelegate
@synthesize window, viewController;

- (void)applicationDidFinishLaunching (UIApplication *)application {

UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:viewController] autorelease];
[window addSubview:navController.view];

tabBarController = [[UITabBarController alloc] init];

categoriasViewController *catViewController = [[categoriasViewController alloc] initWithNibName:@"categoriasView" bundle:nil];
catViewController.title = @"Categorias";

negociosViewController *negViewController = [[negociosViewController alloc] initWithNibName:@"negociosView" bundle:nil];
negViewController.title = @"Negocios";

sitiosViewController *sitViewController = [[sitiosViewController alloc] initWithNibName:@"sitiosView" bundle:nil];
sitViewController.title = @"Sitios";

favoritosViewController *favViewController = [[favoritosViewController alloc] initWithNibName:@"favoritosView" bundle:nil];
favViewController.title = @"Favoritos";

randomViewController *ranViewController = [[randomViewController alloc] initWithNibName:@"randomView" bundle:nil];
ranViewController.title = @"Random";

tabBarController.viewControllers = [NSArray arrayWithObjects:catViewController, negViewController, sitViewController, favViewController, ranViewController, nil];

[catViewController release];
[negViewController release];
[sitViewController release];
[favViewController release];
[ranViewController release];

[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
}

- (void)dealloc {
[tabBarController release];
[window release];
[super dealloc];
}

@end

VIEW WHIT TABLEVIEW

categorias.h
#import <UIKit/UIKit.h>
@interface categoriasViewController : UIViewController {
IBOutlet UITableView *tblSimpleTable;
NSArray *arryData;
}
@end

categorias.m
#import "categoriasViewController.h"
#import "nextCatViewController.h"

@implementation categoriasViewController

- (void)viewDidLoad {
arryData = [[NSArray alloc] initWithObjects:@"iPhone",@"iPod",@"MacBook",@"Mac Book Pro",nil];
[super viewDidLoad];
}

- (NSInteger)numberOfSectionsInTableView (UITableView *)tableView {
return 1;
}


- (void)dealloc {
[super dealloc];
}


// Customize the number of rows in the table view.
- (NSInteger)tableView (UITableView *)tableView numberOfRowsInSection(NSInteger)section {
return [arryData count];
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}

// Set up the cell...
UIImage *image = [UIImage imageNamed:@"icon.png"];
cell.image = image;
cell.text = [arryData objectAtIndex:indexPath.row];
return cell;
}

- (void)tableView (UITableView *)tableView didSelectRowAtIndexPathNSIndexPath *)indexPath {
nextCatViewController *nextController = [[nextCatViewController alloc] initWithNibName:@"nextCatView" bundle:nil];
[self.navigationController pushViewController:nextController animated:YES];
[nextController changeProductText:[arryData objectAtIndex:indexPath.row]];
}

@end

VIEW DETAIL DATA -> NAVIGATION ACTION

.h
#import <UIKit/UIKit.h>
@interface nextCatViewController : UIViewController {
IBOutlet UILabel *lblProductTxt;
}

- (IBAction) changeProductTextNSString *)str;
@end

.m
#import "nextCatViewController.h"


@implementation nextCatViewController

- (void)dealloc {
[super dealloc];
}

- (IBAction) changeProductText (NSString *)str{
lblProductTxt.text = str;
}

@end

THANKS FOR HELP.
gunther is offline   Reply With Quote
Old 06-26-2009, 02:43 PM   #2 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 536
Default

Can you post your code within code tags so everyone can read it? That will really help.
eddietr is offline   Reply With Quote
Old 06-26-2009, 03:07 PM   #3 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 196
Default

here de code

MEGAUPLOAD - The leading online storage and file delivery service

so, you can see what the tab bar and de binding table views works fine.. the problem is what i click in to the cell to the table view but the app not send me at the other view page.. and i include the control navigation and the action...

other question, in the firts view i like a workspace whit 3 controls.. how can make what this space fade in/fade out?

tnks
gunther is offline   Reply With Quote
Old 06-26-2009, 03:47 PM   #4 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 536
Default

Well, there are a couple issues there that I see.

One is that there is no relationship between categoriasViewController and your navController. So within categoriasViewController, you try to do this:

Code:
[self.navigationController pushViewController:nextController animated:YES];
But in fact there is no self.navigationController because this categoriasViewController is not associated with a navigation controller.

Second issue is that in the tableview in categoriasView.nib does not have its delegate property set. So there is never a call made to didSelectRowAtIndexPath.

Once you fix those, there may be other issues as well. But that's a start for you I hope.
eddietr is offline   Reply With Quote
Old 06-26-2009, 03:59 PM   #5 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 196
Default

ok, tnahks i make this change. in the categorias nib relation whit the delegate.. but the relation in the navcontroller and categorias yes exists check the final .m for categorias..this fine? or i write wrong?

now i copy this self logic to negocios.. but self happend.. when click in the cell row of table voe notinhgs happen.. not open the next view..
gunther is offline   Reply With Quote
Old 06-26-2009, 04:09 PM   #6 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 536
Default

Quote:
Originally Posted by gunther View Post
ok, tnahks i make this change. in the categorias nib relation whit the delegate.. but the relation in the navcontroller and categorias yes exists check the final .m for categorias..this fine? or i write wrong?
Unless you changed something since you posted the project, there is no relationship between the categorias controller and the nav controller. In other words, the categorias controller does not have a nav controller controlling it.

Quote:
now i copy this self logic to negocios.. but self happend.. when click in the cell row of table voe notinhgs happen.. not open the next view..
What do you mean by "self logic" and "self happened"? Maybe you could just post the code that you changed? No need to post the whole project, just post the code you changed in your post with code tags so everyone can read it more easily.
eddietr is offline   Reply With Quote
Old 06-26-2009, 04:32 PM   #7 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 196
Default

i check the code what you post.. but not understand... in wich site make a relation between categoriascontroller and navcontroller?
gunther is offline   Reply With Quote
Old 06-26-2009, 06:58 PM   #8 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 196
Default

Ok problem partial solved... ready funciontion what just click in the cell the table view, the app show me the next view.. but i need a problem.. in the next view not show me the back button for go to the previous view..

this the code modifed for run the re send.. now what do?

- (void)tableViewUITableView *)tableView didSelectRowAtIndexPathNSIndexPath *)indexPath {
nextCateViewController *nextController = [[nextCateViewController alloc] initWithNibName:@"nextCateView" bundle:nil];
[self.view addSubview:[nextController view]];
}
gunther is offline   Reply With Quote
Old 06-26-2009, 08:25 PM   #9 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 536
Default

Quote:
Originally Posted by gunther View Post
Ok problem partial solved... ready funciontion what just click in the cell the table view, the app show me the next view.. but i need a problem.. in the next view not show me the back button for go to the previous view..

this the code modifed for run the re send.. now what do?

- (void)tableViewUITableView *)tableView didSelectRowAtIndexPathNSIndexPath *)indexPath {
nextCateViewController *nextController = [[nextCateViewController alloc] initWithNibName:@"nextCateView" bundle:nil];
[self.view addSubview:[nextController view]];
}
Ok, you're on the wrong track unfortunately. If you want a navigation stack, you shouldn't just add the next controller's view as a subview.

So, first thing is I'll explain the code tags. When you post on this forum there is a button above the textbox that is labelled '#'. This is in the toolbar two buttons left of the little 'php' button. If you use that, it looks like this:

Code:
[self.dog bark:once withAnger: YES];
which makes your code much easier to read for everyone who might be trying to help. So please learn to use that and you'll soon have many experts trying to help you.

So, the issue here is that your categorias view is not part of a navigation stack. It is not on the stack of any navigation controller.

The problem goes back to your applicationDidFinishLaunching method in your app delegate. If you look carefully at that, what you have done is this:
  • You created a nav controller
  • You added it to the window
  • You then created a tab bar controller
  • You added a categorias view controller as the first tab of the tab bar controller
  • (you added other controllers to other tabs)
  • Then you put the tab bar controller's view on top of the navigation controller.

So now the navigation controller is basically gone. It's just hidden back there behind the tab bar controller and the user has no access to it anymore.

What you want is for the navigation controller to be attached to the first tab of the tab bar controller. So when you create your array of controllers that you use to set up the tab bar controller, the navigation controller should be the first item in that array.

And that navigation controller should have your categorias view controller as it's root controller. That establishes it on the navigation stack. Then you can push your detail view controller into that stack and you get the back button you want and so on. And then when the user hits the back button, that detail view controller will be popped and you'll be back at the categories view and so on.

That's how a navigation controller works. I hope that helps.

Last edited by eddietr; 06-26-2009 at 08:28 PM.
eddietr is offline   Reply With Quote
Old 06-26-2009, 09:28 PM   #10 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 196
Default

thanks for your time.. i understand hope how the controll works and the problem, is what the navcontroller its hidden for the tabcontroller in the metodh applicationDidFinishLaunching in the delegate.

the view categorias is the root controller, so understand what the next code has deployed in to file the delegate but after to the the next instruction?

tabBarController = [[UITabBarController alloc] init];

categoriasViewController *catViewController = [[categoriasViewController alloc] initWithNibName:@"categoriasView" bundle:nil];
catViewController.title = @"Categorias";

code stack..
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:viewController] autorelease];
[window addSubview:navController.view];

but in the file categoriasview, what code put? nd in what place?
Excuse me but my english its not the better.. but if i understand fine.. hope...

Last edited by gunther; 06-26-2009 at 09:35 PM.
gunther is offline   Reply With Quote
Old 06-26-2009, 09:53 PM   #11 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 536
Default

So to be honest I didn't quite understand what you said there. And it's entirely possible that you didn't understand what I wrote either.

So I'll just try to explain it again and see if that helps?

So your categorias view controller needs to the root controller of your nav controller.

So right now you do this:

Code:
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
When it really should be more like this:

Code:
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:catViewController];
See how you should specify your categorias controller as your root controller when you create your UINavigationController?

Of course this means you need to do this after you have created your categorias controller.

Then that nav controller needs to be the first tab in your tab bar controller.

So right now you have this:

Code:
    tabBarController.viewControllers = [NSArray arrayWithObjects:catViewController, negViewController, sitViewController, favViewController, ranViewController, nil];
but really what you should do is more like this:

Code:
    tabBarController.viewControllers = [NSArray arrayWithObjects:navController, negViewController, sitViewController, favViewController, ranViewController, nil];
You see the navController should be first, not the catViewController. That's where your mistake is.

Also, you shouldn't add the navController's view to the window directly. So just delete this line all together:

Code:
	[window addSubview:navController.view];
That line needs to go because you're adding your tab bar controller's view to the window instead. That view is what should be the top of the hierarchy.
eddietr is offline   Reply With Quote
Old 06-26-2009, 10:04 PM   #12 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 536
Default

By the way, I see you're still not using the code tags that I pointed out twice. Which is a clue to me that we're not really communicating well. I'm not sure how to solve that issue.
eddietr is offline   Reply With Quote
Old 06-29-2009, 02:10 PM   #13 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 196
Default

Hi, ok i executethe the changes what you tell me but the navigation not functionally yet..

i have a dude whit this..

in the delegate.h after at the import of <u.kit>put this code,

Code:
@class categoriasViewController;
after in the declare of interface
Code:
categoriasViewController *viewController;
and after make the properties
Code:
@property (nonatomic, retain) categoriasViewController *viewController;
so, in the delegate.m synthetize viewController, and pass UINavigationController,

Code:
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
so.. i think what this code have the same functionallity?

Now when i attach the controller navigation, i modified the nes code when create the tabbar...

Code:
navController  = [[categoriasViewController alloc] initWithNibName:@"categoriasView" bundle:nil];
navController.title = @"Categorias";

tabBarController.viewControllers = [NSArray arrayWithObjects:navController, negViewController, sitViewController, favViewController, ranViewController, nil];
Now, i apply your code but the the navigation not works..

Last edited by gunther; 06-29-2009 at 02:20 PM.
gunther is offline   Reply With Quote
Old 06-29-2009, 08:14 PM   #14 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 536
Default

Well you defined navController twice! Once as a nav controller and then a second time as a categoriasViewController.
eddietr is offline   Reply With Quote
Old 06-29-2009, 09:01 PM   #15 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 196
Default

ok i cheked.. and tell it works..
gunther is offline   Reply With Quote
Old 06-29-2009, 09:05 PM   #16 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 536
Default

Quote:
Originally Posted by gunther View Post
ok i cheked.. and tell it works..
Wait, I dont' understand what you said. Does it work now?
eddietr is offline   Reply With Quote
Old 07-09-2009, 11:11 AM   #17 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 196
Default

Not works!!!!
gunther is offline   Reply With Quote
Old 07-09-2009, 11:23 AM   #18 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 536
Default

Quote:
Originally Posted by gunther View Post
Not works!!!!
Ok, did you fix the issue I identified in post #14?
eddietr is offline   Reply With Quote
Old 07-09-2009, 11:48 AM   #19 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 196
Default

Quote:
Originally Posted by eddietr View Post
Ok, did you fix the issue I identified in post #14?
Edditer, thansk for your help, the problem its solved, the problem whas in the secuence or order in the which i add the nav controller and viewcontrollers at the tabbar..

thanks.. now i have other dude.. how i can add a new button at the navcontroller, i put this..but i need what click this button go to action, and change the labeltext button,

Code:
	self.navigationItem.rightBarButtonItem = self.editButtonItem;
gunther is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 24,234
Threads: 39,012
Posts: 171,109
Top Poster: smasher (2,570)
Welcome to our newest member, Hunkawebsolution
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:31 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0