Return to Snippet

Revision: 27784
at June 23, 2010 19:29 by devb0yax


Updated Code
.h file:
@interface ResultsViewController : UITableViewController 
{
	NSMutableArray	*m_list;
}

@property(nonatomic,retain)	NSMutableArray	*m_list;

@end

=======================
.m file:

@implementation ResultsViewController


//@synthesize m_resultsDetailViewController;
@synthesize m_list;
//@synthesize m_resultCellDict;

#pragma mark -
#pragma mark View lifecycle


- (void)viewDidLoad {
    [super viewDidLoad];
	
	NSDictionary *tempDict;
	AdInfo *shAdInfo =  [AdInfo sharedAdInfo];
	tempDict = shAdInfo.adInfoDict;
	int nCountDict = [tempDict count];
	NSLog(@"nCountDict: %d", nCountDict);
	////////////////////////
	NSMutableArray *myMutableArr = [[NSMutableArray alloc] init];
	int ctr;
	NSDictionary *localDict;
	
	for(ctr = 1; ctr <= nCountDict; ctr++)
	{
		localDict = [tempDict objectForKey:[NSString stringWithFormat:@"%d", ctr]];
		[myMutableArr addObject:localDict];
	}
	
	self.m_list = myMutableArr;
	[myMutableArr release];
	
	NSLog(@"m_list count: %d", [m_list count]);
}


#pragma mark -
#pragma mark Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return [m_list count];
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    
    // Configure the cell...
	NSUInteger row = [indexPath row];		
	NSDictionary *newDict = [NSDictionary dictionaryWithDictionary:[m_list objectAtIndex:row]];
	
	//NSLog(@"newDict desc: %@", [newDict description]);
	NSString *rowString = [newDict objectForKey:@"title"];
	cell.textLabel.text = rowString;	
	[rowString release];
		
    return cell;
}


#pragma mark -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Navigation logic may go here. Create and push another view controller.
	NSUInteger row = [indexPath row];
	NSDictionary *rowDetails = [NSDictionary dictionaryWithDictionary:[m_list objectAtIndex:row]];
	ResultsDetailViewController *resultsDetailViewController = [[ResultsDetailViewController alloc] initWithNibName:@"ResultsDetailView" bundle:nil withDictionary:rowDetails];
	
     // Pass the selected object to the new view controller.
	[self.navigationController pushViewController:resultsDetailViewController animated:YES];
	[resultsDetailViewController release];
	resultsDetailViewController = nil;
	//[rowDetails release];
	//rowDetails = nil;
}


#pragma mark -
#pragma mark Memory management
- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Relinquish ownership any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
    // For example: self.myOutlet = nil;
	self.m_list = nil;
	[super viewDidUnload];
}


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

Revision: 27783
at June 23, 2010 19:27 by devb0yax


Initial Code
.h file:
@interface ResultsViewController : UITableViewController 
{
	NSMutableArray	*m_list;
}

@property(nonatomic,retain)	NSMutableArray	*m_list;

@end

=======================
.m file:

@implementation ResultsViewController


//@synthesize m_resultsDetailViewController;
@synthesize m_list;
//@synthesize m_resultCellDict;

#pragma mark -
#pragma mark View lifecycle


- (void)viewDidLoad {
    [super viewDidLoad];
	
	NSDictionary *tempDict;
	AdInfo *shAdInfo =  [AdInfo sharedAdInfo];
	tempDict = shAdInfo.adInfoDict;
	int nCountDict = [tempDict count];
	NSLog(@"nCountDict: %d", nCountDict);
	////////////////////////
	NSMutableArray *myMutableArr = [[NSMutableArray alloc] init];
	int ctr;
	NSDictionary *localDict;
	
	for(ctr = 1; ctr <= nCountDict; ctr++)
	{
		localDict = [tempDict objectForKey:[NSString stringWithFormat:@"%d", ctr]];
		[myMutableArr addObject:localDict];
	}
	
	self.m_list = myMutableArr;
	[myMutableArr release];
	
	NSLog(@"m_list count: %d", [m_list count]);
}


#pragma mark -
#pragma mark Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return [m_list count];
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    
    // Configure the cell...
	NSUInteger row = [indexPath row];		
	NSDictionary *newDict = [NSDictionary dictionaryWithDictionary:[m_list objectAtIndex:row]];
	
	//NSLog(@"newDict desc: %@", [newDict description]);
	NSString *rowString = [newDict objectForKey:@"ads_title"];
	cell.textLabel.text = rowString;	
	[rowString release];
		
    return cell;
}


#pragma mark -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Navigation logic may go here. Create and push another view controller.
	NSUInteger row = [indexPath row];
	NSDictionary *rowDetails = [NSDictionary dictionaryWithDictionary:[m_list objectAtIndex:row]];
	ResultsDetailViewController *resultsDetailViewController = [[ResultsDetailViewController alloc] initWithNibName:@"ResultsDetailView" bundle:nil withDictionary:rowDetails];
	
     // Pass the selected object to the new view controller.
	[self.navigationController pushViewController:resultsDetailViewController animated:YES];
	[resultsDetailViewController release];
	resultsDetailViewController = nil;
	//[rowDetails release];
	//rowDetails = nil;
}


#pragma mark -
#pragma mark Memory management
- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Relinquish ownership any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
    // For example: self.myOutlet = nil;
	self.m_list = nil;
	[super viewDidUnload];
}


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

Initial URL


Initial Description


Initial Title
didSelectRowAtIndexPath crash!

Initial Tags


Initial Language
iPhone