Posted By


devb0yax on 06/23/10

Tagged


Statistics


Viewed 176 times
Favorited by 0 user(s)

didSelectRowAtIndexPath crash!


/ Published in: iPhone
Save to your folder(s)



Copy this code and paste it in your HTML
  1. .h file:
  2. @interface ResultsViewController : UITableViewController
  3. {
  4. NSMutableArray *m_list;
  5. }
  6.  
  7. @property(nonatomic,retain) NSMutableArray *m_list;
  8.  
  9. @end
  10.  
  11. =======================
  12. .m file:
  13.  
  14. @implementation ResultsViewController
  15.  
  16.  
  17. //@synthesize m_resultsDetailViewController;
  18. @synthesize m_list;
  19. //@synthesize m_resultCellDict;
  20.  
  21. #pragma mark -
  22. #pragma mark View lifecycle
  23.  
  24.  
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27.  
  28. NSDictionary *tempDict;
  29. AdInfo *shAdInfo = [AdInfo sharedAdInfo];
  30. tempDict = shAdInfo.adInfoDict;
  31. int nCountDict = [tempDict count];
  32. NSLog(@"nCountDict: %d", nCountDict);
  33. ////////////////////////
  34. NSMutableArray *myMutableArr = [[NSMutableArray alloc] init];
  35. int ctr;
  36. NSDictionary *localDict;
  37.  
  38. for(ctr = 1; ctr <= nCountDict; ctr++)
  39. {
  40. localDict = [tempDict objectForKey:[NSString stringWithFormat:@"%d", ctr]];
  41. [myMutableArr addObject:localDict];
  42. }
  43.  
  44. self.m_list = myMutableArr;
  45. [myMutableArr release];
  46.  
  47. NSLog(@"m_list count: %d", [m_list count]);
  48. }
  49.  
  50.  
  51. #pragma mark -
  52. #pragma mark Table view data source
  53. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  54. // Return the number of sections.
  55. return 1;
  56. }
  57.  
  58. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  59. // Return the number of rows in the section.
  60. return [m_list count];
  61. }
  62.  
  63.  
  64. // Customize the appearance of table view cells.
  65. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  66. {
  67.  
  68. static NSString *CellIdentifier = @"Cell";
  69.  
  70. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  71. if (cell == nil) {
  72. cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
  73. }
  74.  
  75. // Configure the cell...
  76. NSUInteger row = [indexPath row];
  77. NSDictionary *newDict = [NSDictionary dictionaryWithDictionary:[m_list objectAtIndex:row]];
  78.  
  79. //NSLog(@"newDict desc: %@", [newDict description]);
  80. NSString *rowString = [newDict objectForKey:@"title"];
  81. cell.textLabel.text = rowString;
  82. [rowString release];
  83.  
  84. return cell;
  85. }
  86.  
  87.  
  88. #pragma mark -
  89. #pragma mark Table view delegate
  90. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  91. // Navigation logic may go here. Create and push another view controller.
  92. NSUInteger row = [indexPath row];
  93. NSDictionary *rowDetails = [NSDictionary dictionaryWithDictionary:[m_list objectAtIndex:row]];
  94. ResultsDetailViewController *resultsDetailViewController = [[ResultsDetailViewController alloc] initWithNibName:@"ResultsDetailView" bundle:nil withDictionary:rowDetails];
  95.  
  96. // Pass the selected object to the new view controller.
  97. [self.navigationController pushViewController:resultsDetailViewController animated:YES];
  98. [resultsDetailViewController release];
  99. resultsDetailViewController = nil;
  100. //[rowDetails release];
  101. //rowDetails = nil;
  102. }
  103.  
  104.  
  105. #pragma mark -
  106. #pragma mark Memory management
  107. - (void)didReceiveMemoryWarning {
  108. // Releases the view if it doesn't have a superview.
  109. [super didReceiveMemoryWarning];
  110.  
  111. // Relinquish ownership any cached data, images, etc that aren't in use.
  112. }
  113.  
  114. - (void)viewDidUnload {
  115. // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
  116. // For example: self.myOutlet = nil;
  117. self.m_list = nil;
  118. [super viewDidUnload];
  119. }
  120.  
  121.  
  122. - (void)dealloc {
  123. [m_list release];
  124. [super dealloc];
  125. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.