Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  RootViewController.m
  3. //  CoreDataTest
  4. //
  5. //  Created by Brent Hosie on 10/1/10.
  6. //  Copyright 2010 University Of Utah. All rights reserved.
  7. //
  8.  
  9. #import "RootViewController.h"
  10. #import "Occupation.h"
  11. #import "Topic.h"
  12. #import "OKWebViewController.h"
  13. #import "DetailViewController.h"
  14.  
  15.  
  16. @implementation RootViewController
  17. @synthesize occupationInfo;
  18. @synthesize topicInfo;
  19. @synthesize context;
  20.  
  21.  
  22. #pragma mark -
  23. #pragma mark Initialization
  24.  
  25. /*
  26. - (id)initWithStyle:(UITableViewStyle)style {
  27.     // Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
  28.     if ((self = [super initWithStyle:style])) {
  29.     }
  30.     return self;
  31. }
  32. */
  33.  
  34.  
  35. #pragma mark -
  36. #pragma mark View lifecycle
  37.  
  38.  
  39. - (void)viewDidLoad {
  40.     [super viewDidLoad];
  41.    
  42.     NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
  43.     NSEntityDescription *entity = [NSEntityDescription
  44.                                    entityForName:@"Occupation" inManagedObjectContext:context];
  45.     [fetchRequest setEntity:entity];
  46.     NSError *error;
  47.     self.occupationInfo = [context executeFetchRequest:fetchRequest error:&error];
  48.     self.title = @"Occupations";
  49.    
  50.     [fetchRequest release];
  51.  
  52.     // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
  53.     // self.navigationItem.rightBarButtonItem = self.editButtonItem;
  54. }
  55.  
  56.  
  57. /*
  58. - (void)viewWillAppear:(BOOL)animated {
  59.     [super viewWillAppear:animated];
  60. }
  61. */
  62. /*
  63. - (void)viewDidAppear:(BOOL)animated {
  64.     [super viewDidAppear:animated];
  65. }
  66. */
  67. /*
  68. - (void)viewWillDisappear:(BOOL)animated {
  69.     [super viewWillDisappear:animated];
  70. }
  71. */
  72. /*
  73. - (void)viewDidDisappear:(BOOL)animated {
  74.     [super viewDidDisappear:animated];
  75. }
  76. */
  77. /*
  78. // Override to allow orientations other than the default portrait orientation.
  79. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  80.     // Return YES for supported orientations
  81.     return (interfaceOrientation == UIInterfaceOrientationPortrait);
  82. }
  83. */
  84.  
  85.  
  86. #pragma mark -
  87. #pragma mark Table view data source
  88.  
  89. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  90.     // Return the number of sections.
  91.     return 1;
  92. }
  93.  
  94.  
  95. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  96.     // Return the number of rows in the section.
  97.     return [occupationInfo count];
  98. }
  99.  
  100.  
  101. // Customize the appearance of table view cells.
  102. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  103.    
  104.     static NSString *CellIdentifier = @"Cell";
  105.    
  106.     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  107.     if (cell == nil) {
  108.         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
  109.     }
  110.    
  111.     // Configure the cell...
  112.     Occupation *occ = [occupationInfo objectAtIndex:indexPath.row];
  113.     cell.textLabel.text = occ.occName;
  114.    
  115.     return cell;
  116. }
  117.  
  118.  
  119. /*
  120. // Override to support conditional editing of the table view.
  121. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
  122.     // Return NO if you do not want the specified item to be editable.
  123.     return YES;
  124. }
  125. */
  126.  
  127.  
  128. /*
  129. // Override to support editing the table view.
  130. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  131.    
  132.     if (editingStyle == UITableViewCellEditingStyleDelete) {
  133.         // Delete the row from the data source
  134.         [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
  135.     }  
  136.     else if (editingStyle == UITableViewCellEditingStyleInsert) {
  137.         // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
  138.     }  
  139. }
  140. */
  141.  
  142.  
  143. /*
  144. // Override to support rearranging the table view.
  145. - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
  146. }
  147. */
  148.  
  149.  
  150. /*
  151. // Override to support conditional rearranging of the table view.
  152. - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
  153.     // Return NO if you do not want the item to be re-orderable.
  154.     return YES;
  155. }
  156. */
  157.  
  158.  
  159. #pragma mark -
  160. #pragma mark Table view delegate
  161.  
  162. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  163.     // Navigation logic may go here. Create and push another view controller.
  164.     Occupation *occ = [occupationInfo objectAtIndex:indexPath.row];
  165.  
  166.    
  167.     /*UIAlertView *alert = [[UIAlertView alloc]
  168.                           initWithTitle:@"You Pushed the Following Button!"
  169.                           message:(@"%@", occ.occName)
  170.                           delegate:self
  171.                           cancelButtonTitle:@"OK"
  172.                           otherButtonTitles:nil];
  173.     [alert show];
  174.     [alert release];*/     
  175.    
  176.     NSLog(@"you pushed the %@ button", occ.occName );
  177.    
  178.    
  179.    
  180.     //NSSet *theTopicName = [topicInfo valueForKey:@"tName"];
  181.    
  182.     //TODO: Pass this stuff to the DetailViewController
  183.     NSManagedObject *theObject = occ.self;
  184.     NSSet *occTopicsName = [theObject valueForKeyPath:@"topics.tName"];
  185.     NSSet *occTopicsURL = [theObject valueForKeyPath:@"topics.tURL"];
  186.    
  187.     //NSLog(@"%@", theObject);
  188.     //NSLog(@"%@", occTopicsName);
  189.     //NSLog(@"%@", occTopicsURL);
  190.    
  191.        
  192.    
  193.    
  194.      DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:nil bundle:nil];
  195.     detailViewController.theObject = theObject;
  196.     // ...
  197.      // Pass the selected object to the new view controller.
  198.      [self.navigationController pushViewController:detailViewController animated:YES];
  199.      [detailViewController release];
  200.    
  201. }
  202.  
  203.  
  204. #pragma mark -
  205. #pragma mark Memory management
  206.  
  207. - (void)didReceiveMemoryWarning {
  208.     // Releases the view if it doesn't have a superview.
  209.     [super didReceiveMemoryWarning];
  210.    
  211.     // Relinquish ownership any cached data, images, etc that aren't in use.
  212. }
  213.  
  214. - (void)viewDidUnload {
  215.     // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
  216.     // For example: self.myOutlet = nil;
  217. }
  218.  
  219.  
  220. - (void)dealloc {
  221.     [super dealloc];
  222. }
  223.  
  224.  
  225. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement