Advertisement
Guest User

IOS grouped tableview transparent cells

a guest
Jul 12th, 2013
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #import "LeftSideMenuViewController.h"
  3. #import "KeepVCSingleton.h"
  4. #import "SettingsViewController.h"
  5. #import "MFSideMenu.h"
  6. #import "SettingNavigationViewController.h"
  7. #import <QuartzCore/QuartzCore.h>
  8.  
  9.  
  10.  
  11. NSString * const NOTIF_offlineModeEdited =@"offlineModeEdited";
  12.  
  13. /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  14.  * offlineModeEdited
  15.  *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
  16.  
  17. @interface LeftSideMenuViewController ()
  18. @property (nonatomic, strong) NSMutableArray *menuItems;
  19. @end
  20.  
  21. @interface LeftSideMenuViewController (private)
  22. - (void)offlineModeEdited:(NSNotification *)notif;
  23. @end
  24.  
  25. @implementation LeftSideMenuViewController
  26.  
  27. @synthesize delegate;
  28.  
  29. - (void)awakeFromNib
  30. {
  31.     self.menuItems = [NSMutableArray arrayWithObjects:@"Events", @"Documents", @"Calendar",@"Offline Mode",nil];
  32.     KeepVCSingleton *shrd= [KeepVCSingleton sharedInstance];
  33.     shrd.leftVc=self;
  34.    
  35.    
  36.    
  37. }
  38. - (id)initWithStyle:(UITableViewStyle)style
  39. {
  40.     self = [super initWithStyle:style];
  41.     if (self) {
  42.         // Custom initialization
  43.     }
  44.     return self;
  45. }
  46.  
  47. - (void)viewDidLoad
  48. {
  49.     [super viewDidLoad];
  50.    
  51.     //background image
  52. //    self.view.backgroundColor= [UIColor clearColor];
  53. //    self.view.backgroundColor=[[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"menu_background.png"]];
  54.    
  55.    [self.tableView setBackgroundView:nil];
  56.     self.tableView.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"menu_background.png"]];
  57.  
  58.  
  59.     //background image
  60.     //self.view.backgroundColor= [UIColor clearColor];
  61.     //self.view.backgroundColor=[[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"Backgroundwithout Logo.png"]];
  62.     //self.tableView.backgroundColor=nil;
  63.     // Register observer to be called when logging out
  64.     [[NSNotificationCenter defaultCenter] addObserver:self
  65.                                              selector:@selector(offlineModeEdited:)
  66.                                                  name:NOTIF_offlineModeEdited object:nil];
  67.    
  68.    
  69.    
  70.     //[self testOfflineOption];
  71.    
  72. }
  73. - (void)offlineModeEdited:(NSNotification *)notif{
  74.    
  75.     NSLog(@"offlineModeEdited: recieved");
  76.     //[self testOfflineOption];
  77. }
  78.  
  79.  
  80.  
  81. //Checks if we have an internet connection or not
  82. - (void)testOfflineOption
  83. {
  84.  
  85.     if ([[NSUserDefaults standardUserDefaults] boolForKey:@"OfflineMode"]==NO) {
  86.         [self dismissOfflineMode];
  87.     }
  88.     else
  89.     {
  90.          [self showOfflienMode];
  91.     }
  92.    
  93.  
  94. }
  95.  
  96. -(void) showOfflienMode
  97. {
  98.     //maybe animation while adding row?
  99.    
  100.     if (![self.menuItems containsObject:@"Offline Mode"]){
  101.         [self.menuItems addObject:@"Offline Mode"];
  102.     }
  103.     [self.tableView reloadData];
  104. }
  105.  
  106. -(void)dismissOfflineMode
  107. {
  108.     if ([self.menuItems containsObject:@"Offline Mode"]) {
  109.         [self.menuItems removeObject:@"Offline Mode"];
  110.     }
  111.    
  112.     [self.tableView reloadData];
  113. }
  114.  
  115.  
  116.  
  117.  
  118. - (void)didReceiveMemoryWarning
  119. {
  120.     [super didReceiveMemoryWarning];
  121.     // Dispose of any resources that can be recreated.
  122. }
  123.  
  124. #pragma mark - Table view data source
  125. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  126. {
  127.     return 2;
  128. }
  129.  
  130. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  131. {
  132.     if (section==0) {
  133.         return [self.menuItems count];
  134.     }
  135.     else
  136.         return 1;
  137. }
  138. // set header height of gropued tableview
  139. -(CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section {
  140.    
  141.     if (section==0) {
  142.         return 80;
  143.     }
  144.     else
  145.         return 120;
  146. }
  147. //row height
  148. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  149.     return 110.0;
  150. }
  151.  
  152.  
  153. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  154. {
  155.     NSString *cellIdentifier = @"Cell";
  156.     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
  157.     if (cell == nil) {
  158.         cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
  159.     }
  160.     cell.selectionStyle = UITableViewCellSelectionStyleGray;
  161.    
  162.     UIFont* rightFont =[UIFont fontWithName:@"Gill Sans" size:14];
  163.     UIColor* rightColor = [UIColor whiteColor];
  164.    
  165.     UILabel *hasInvitedYouText=[[UILabel alloc] initWithFrame:CGRectMake(5.0f, 75.0f, 195.0f, 25.0f)];
  166.     hasInvitedYouText.font=rightFont;
  167.     hasInvitedYouText.textColor=rightColor;
  168.     hasInvitedYouText.backgroundColor=[UIColor clearColor];
  169.     hasInvitedYouText.textAlignment=UITextAlignmentCenter;
  170.    
  171.     UIImageView *menuImageView;
  172.     UIImage *menuImage;
  173.    
  174.    
  175.     if (indexPath.section==0) {
  176.         hasInvitedYouText.text = [self.menuItems objectAtIndex:indexPath.row];
  177.         switch (indexPath.row) {
  178.             case 0:
  179.                 menuImageView=[[UIImageView alloc] initWithFrame:CGRectMake(50.0f, 20.0f,47.0f, 69.0f)];
  180.                 menuImage=[UIImage imageNamed:@"events_icon.png"];
  181.                 break;
  182.             case 1:
  183.                  menuImageView=[[UIImageView alloc] initWithFrame:CGRectMake(33.0f, 20.0f,82.0f, 68.0f)];
  184.                 menuImage=[UIImage imageNamed:@"document_icon.png"];
  185.                 break;
  186.             case 2:
  187.                  menuImageView=[[UIImageView alloc] initWithFrame:CGRectMake(40.0f, 20.0f,68.0f, 68.0f)];
  188.                 menuImage=[UIImage imageNamed:@"calendar_icon.png"];
  189.                 break;
  190.             case 3:
  191.                     menuImageView=[[UIImageView alloc] initWithFrame:CGRectMake(30.0f, 20.0f,92.0f, 71.0f)];
  192.                     menuImage=[UIImage imageNamed:@"offline_icon.png"];
  193.                 break;
  194.                
  195.             default:
  196.                 break;
  197.         }
  198.        // cell.textLabel.text = [self.menuItems objectAtIndex:indexPath.row];
  199.     }
  200.     else{
  201.         menuImageView=[[UIImageView alloc] initWithFrame:CGRectMake(50.0f, 20.0f,58.0f, 71.0f)];
  202.         hasInvitedYouText.text = @"Settings";
  203.         menuImage=[UIImage imageNamed:@"settings_icon.png"];
  204.     }
  205.    
  206.     menuImageView.image=menuImage;
  207.     [cell.contentView addSubview:menuImageView];
  208.    
  209.     [hasInvitedYouText sizeToFit];
  210.     //[cell.contentView addSubview:hasInvitedYouText];
  211.    
  212. //    cell.backgroundColor = [UIColor clearColor];
  213. //    cell.layer.backgroundColor = [UIColor clearColor].CGColor;
  214.    
  215. //    
  216. //    [[cell imageView] setBackgroundColor:[UIColor clearColor]];
  217. //    [cell setBackgroundColor:[UIColor clearColor]];
  218.    
  219.     // [self.tableView setBackgroundView:nil];
  220.    
  221.     cell.textLabel.text=nil;
  222.     return cell;
  223. }
  224. //transparentcells
  225. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  226. {
  227.     cell.backgroundColor = [UIColor clearColor];
  228. }
  229. //transparent headers
  230. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  231. {
  232.    
  233.     UIImage *myImage = [UIImage imageNamed:@""];
  234.     UIImageView *imageView = [[UIImageView alloc] initWithImage:myImage];
  235.     imageView.frame = CGRectMake(10,10,300,100);
  236.    
  237.     return imageView;
  238.    
  239. }
  240.  
  241.  
  242. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
  243. {
  244.     // Return NO if you do not want the specified item to be editable.
  245.     return NO;
  246. }
  247.  
  248. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  249. {
  250.     //this sends object info to detail
  251.     if (indexPath.section==0) {
  252.         [delegate changeTab:indexPath.row];
  253.     }
  254.     else{
  255.         [self settingPopOverControl];
  256.     }
  257.     //deselect selected row
  258.     [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
  259. }
  260.  
  261. //call settings form sheet viewcontroller
  262. -(void)settingPopOverControl
  263. {
  264.    
  265.     UIStoryboard*  sb = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
  266.     SettingNavigationViewController *settingsVC = [sb instantiateViewControllerWithIdentifier:@"SettingNavigation"];
  267.     //add navigation controller
  268. //    UINavigationController *modalViewNavController= [[UINavigationController alloc] initWithRootViewController:settingsVC];
  269. //    modalViewNavController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
  270. //  modalViewNavController.modalPresentationStyle = UIModalPresentationFormSheet;
  271. //  [self presentModalViewController:modalViewNavController animated:YES];
  272.    
  273.     //added navigation controller in storyboard no need to create it programmatically again
  274.     settingsVC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
  275.     settingsVC.modalPresentationStyle = UIModalPresentationFormSheet;
  276.     [self presentModalViewController:settingsVC animated:YES];
  277.    
  278. }
  279.  
  280.  
  281. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement