redribben

playing with tables

Jan 26th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import "ViewController.h"
  2. #import "BMSetting.h"
  3.  
  4. @interface ViewController ()
  5.  
  6. @end
  7.  
  8. @implementation ViewController {
  9.     NSArray *settingArray;
  10. }
  11.  
  12.  
  13.  
  14.  
  15. - (void)viewDidLoad {
  16.     [super viewDidLoad];
  17.    
  18.     // Create settings array
  19.     BMSetting *setting1 = [BMSetting new];
  20.     setting1.name = @"Live Call Confirmation";
  21.     setting1.detail = @"An alert pops up and asks if you are sure that you would like to make to the studio";
  22.     setting1.setOn = @"There will be a pop up that confirms that you really do wish to make the call";
  23.     setting1.setOff = @"The call will go through right away";
  24.  
  25.    
  26.     BMSetting *setting2 = [BMSetting new];
  27.     setting2.name = @"Play On Launch";
  28.     setting2.detail = @"The option to have Radio automatically start playing when the application launches";
  29.     setting1.setOn = @"The radio will start playing when the application launches";
  30.     setting1.setOff = @"The play button will need to have to be clicked for the audio to start playing";
  31.  
  32.    
  33.     BMSetting *setting3 = [BMSetting new];
  34.     setting3.name = @"Allow Landscape Orientation";
  35.     setting3.detail = @"Enables the applications to be used in all orientations";
  36.     setting1.setOn = @"The application could be used when the device is sideways";
  37.     setting1.setOff = @"The application will only work in portrait style";
  38.    
  39.  
  40.    
  41.     settingArray = [NSArray arrayWithObjects:setting1, setting2, setting3, nil];
  42.  
  43.     // Assign our own backgroud for the view
  44.     self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"common_bg"]];
  45.     self.tableView.backgroundColor = [UIColor clearColor];
  46.  
  47.  
  48. }
  49.  
  50. - (void)didReceiveMemoryWarning {
  51.     [super didReceiveMemoryWarning];
  52.     // Dispose of any resources that can be recreated.
  53. }
  54.  
  55. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  56. {
  57.     // Return the number of sections.
  58.     return 1;
  59. }
  60.  
  61.  
  62. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  63. {
  64.     // Return the number of rows in the section.
  65.     return settingArray.count;
  66. }
  67.  
  68. - (UIImage *)cellBackgroundForRowAtIndexPath:(NSIndexPath *)indexPath
  69. {
  70.     NSInteger rowCount = [self tableView:[self tableView] numberOfRowsInSection:0];
  71.     NSInteger rowIndex = indexPath.row;
  72.     UIImage *background = nil;
  73.    
  74.     if (rowIndex == 0) {
  75.         background = [UIImage imageNamed:@"cell_top.png"];
  76.     } else if (rowIndex == rowCount - 1) {
  77.         background = [UIImage imageNamed:@"cell_bottom.png"];
  78.     } else {
  79.         background = [UIImage imageNamed:@"cell_middle.png"];
  80.     }
  81.    
  82.     return background;
  83. }
  84.  
  85.  
  86. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  87. {
  88.     static NSString *CellIdentifier = @"Cell";
  89.     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  90.    
  91.     // Configure the cell...
  92.     if (cell == nil) {
  93.         cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  94.     }
  95.    
  96.     // Display recipe in the table cell
  97.     BMSetting *setting = [settingArray objectAtIndex:indexPath.row];
  98.    
  99.     UILabel *settingNameLabel = (UILabel *)[cell viewWithTag:101];
  100.     settingNameLabel.text = setting.name;
  101.    
  102.     // Assign our own background image for the cell
  103.     UIImage *background = [self cellBackgroundForRowAtIndexPath:indexPath];
  104.    
  105.     UIImageView *cellBackgroundView = [[UIImageView alloc] initWithImage:background];
  106.     cellBackgroundView.image = background;
  107.     cell.backgroundView = cellBackgroundView;
  108.    
  109.    
  110.     return cell;
  111. }
  112.  
  113.  
  114.  
  115. @end
Advertisement
Add Comment
Please, Sign In to add comment