Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jjgraz

macrumors regular
Original poster
Feb 13, 2009
103
0
I have an application which uses a UITabBar with 5 tabs. The UITabBar has within a navigation controller for one of the tabbar items controlling a TableView for that particular view....The TableView then has a disclosure Button which moves to the detailView of selected Cell.
So : TabBarController ->5tabbarButtons one of which is NavigationController -> TableView -> DetailView.

The app gets xml data from my database/webservice and loads it all into each reusable cell to display an accurate history of events for a particular user.

The Problem is: detailView is only showing the first set of details for selected Cell:
In other words, Everything appears fine on the tableView(there are a few labels which display some basic details on each different history event for the user, However, when going on step further into detail view....The Cells in detailView display all the correct detail information for only the first cell selected. So if someone selects entry1 to see details, it displays correctly...but if they go back and then select entry2 after, entry 2 detailvew displays the details of entry1. The detailView Cells are not refreshing and allowing itself to be reused. I have looked my code over and over and can't find the solution. Please let me know if you can help. I very much appreciate it. I have included a bit of code below. Thank you.

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [appDelegate.blts count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

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

*******Some more Code*******
}
return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic -- create and push a new view controller

if(bltController == nil)
bltController = [[BltDetailViewController alloc] initWithNibName:mad:"BltDetailView" bundle:[NSBundle mainBundle]];

*******Some more Code*******

[self.navigationController pushViewController:bltController animated:YES];
}


Thank you.
 

jjgraz

macrumors regular
Original poster
Feb 13, 2009
103
0
Code:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [appDelegate.blts count];	
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

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

*******Some more Code*******	
}
return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic -- create and push a new view controller

if(bltController == nil)
bltController = [[BltDetailViewController alloc] initWithNibName:@"BltDetailView" bundle:[NSBundle mainBundle]];

*******Some more Code*******

[self.navigationController pushViewController:bltController animated:YES];
}
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
Does BltDetailViewController have any code in viewWillAppear or so that updates the data of that detail view? I.E. you need to refresh the data displayed in the detail view when based on which row is selected.
 

jjgraz

macrumors regular
Original poster
Feb 13, 2009
103
0
It does. the following code is in bltDetailViewController.m

Code:
- (void)viewWillAppear:(BOOL)animated {
	[super viewWillAppear:animated];
	
	[tableView reloadData];
}
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
Okay. That'll reload the tableView. What about the detail View? What is BltDetailView? Is it a subclass of UIView, UITableView, what? What kind of elements does it contain?
 

jjgraz

macrumors regular
Original poster
Feb 13, 2009
103
0
bltDetailView is actually another UITableView, and a subclass of UIView in the bltViewController.xib. It contains a bunch of NSStrings which are used to display history items in the bltDetailViews Indexed Table. history items such as(name, date, ect....)
 

jjgraz

macrumors regular
Original poster
Feb 13, 2009
103
0
bltDetailViewController.h

Code:
#import <UIKit/UIKit.h>

@class Blt;

@interface BltDetailViewController : UIViewController {

	IBOutlet UITableView *tableView;
	
	Blt *aBlt;
}

@property (nonatomic, retain) Blt *aBlt;

@end

bltDetailViewController.m

Code:
#import "BltDetailViewController.h"
#import "Blt.h"

@implementation BltDetailViewController

@synthesize aBlt;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
    }
    return self;
}

// Implement viewDidLoad to do additional setup after loading the view.
- (void)viewDidLoad {
    [super viewDidLoad];
	
	self.title = @"Blt Detail";
}

- (void)viewWillAppear:(BOOL)animated {
	[super viewWillAppear:animated];
	[tableView reloadData];
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
}

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


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
		
    }

	switch(indexPath.section)
	
	{
		case 0:
			cell.text = aBlt.firstname;
			break;
		case 1:
			*****ect..******
	
	return cell;
}

- (NSString *)tableView:(UITableView *)tblView titleForHeaderInSection:(NSInteger)section {
	
	NSString *sectionName = nil;
	
	switch(section)
	{
		case 0:
			sectionName = [NSString stringWithString:@"Opp"];
			break;
		case 1:
                         *****ect..******
			
	}
	
	return sectionName;
}

- (void)dealloc {
	
	[aBlt release];
	[tableView release];
    [super dealloc];
}


@end

hope this helps.
 

jjgraz

macrumors regular
Original poster
Feb 13, 2009
103
0
I got it. I do appreciate your thoughts Dejo. I actually had a silly if statement in there that was stopping the reload process. Thanks.
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
I got it. I do appreciate your thoughts Dejo. I actually had a silly if statement in there that was stopping the reload process. Thanks.
You're welcome. Sometimes it helps to post the real code so that we can better troubleshoot the issue. If you've never been stumped by code that doesn't work or you can't understand why until someone else looks at it, you haven't lived as a true programmer yet. :D
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.