Advertisement
redribben

tableView.m

Jan 27th, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //  ViewController.m
  2. //  IBcells
  3.  
  4.  
  5. #import "ViewController.h"
  6. #import "BMSetting.h"
  7.  
  8. @interface ViewController ()
  9.  
  10. @end
  11.  
  12. @implementation ViewController {
  13.     NSArray *settingArray;
  14. }
  15.  
  16.  
  17. //-(id)init {
  18. //    self = [super init];
  19. //    if (self) {
  20. //        //self.tableView = [[UITableView alloc] initWithFrame:self.bounds];
  21. //        //self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  22. //        self.tableView.dataSource = self;
  23. //        self.tableView.delegate = self;
  24. //        //self.tableView.scrollEnabled = NO;
  25. //        //self.tableView.layer.cornerRadius = PanelCornerRadius;
  26. //        //[self addSubview:self.tableView];
  27. //    }
  28. //    return self;
  29. //}
  30.  
  31. - (void)viewDidLoad {
  32.     [super viewDidLoad];
  33.    
  34.     self.tableView.dataSource = self;
  35.     self.tableView.delegate = self;
  36.    
  37.     // Create settings array
  38.     BMSetting *setting1 = [BMSetting new];
  39.     setting1.name = @"Live Call Confirmation";
  40.     setting1.detail = @"An alert pops up and asks if you are sure that you would like to make to the studio";
  41.     setting1.setOn = @"There will be a pop up that confirms that you really do wish to make the call";
  42.     setting1.setOff = @"The call will go through right away";
  43.  
  44.    
  45.     BMSetting *setting2 = [BMSetting new];
  46.     setting2.name = @"Play On Launch";
  47.     setting2.detail = @"The option to have Radio automatically start playing when the application launches";
  48.     setting1.setOn = @"The radio will start playing when the application launches";
  49.     setting1.setOff = @"The play button will need to have to be clicked for the audio to start playing";
  50.  
  51.    
  52.     BMSetting *setting3 = [BMSetting new];
  53.     setting3.name = @"Allow Landscape Orientation";
  54.     setting3.detail = @"Enables the applications to be used in all orientations";
  55.     setting1.setOn = @"The application could be used when the device is sideways";
  56.     setting1.setOff = @"The application will only work in portrait style";
  57.    
  58.  
  59.    
  60.     settingArray = [NSArray arrayWithObjects:setting1, setting2, setting3, nil];
  61.  
  62.     // Assign our own backgroud for the view
  63.     self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"common_bg"]];
  64.     self.tableView.backgroundColor = [UIColor clearColor];
  65.  
  66.  
  67. }
  68.  
  69. - (void)didReceiveMemoryWarning {
  70.     [super didReceiveMemoryWarning];
  71.     // Dispose of any resources that can be recreated.
  72. }
  73.  
  74. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  75. {
  76.     // Return the number of sections.
  77.     return 1;
  78. }
  79.  
  80.  
  81. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  82. {
  83.     // Return the number of rows in the section.
  84.     return settingArray.count;
  85. }
  86.  
  87. - (UIImage *)cellBackgroundForRowAtIndexPath:(NSIndexPath *)indexPath
  88. {
  89.     NSInteger rowCount = [self tableView:[self tableView] numberOfRowsInSection:0];
  90.     NSInteger rowIndex = indexPath.row;
  91.     UIImage *background = nil;
  92.    
  93.     if (rowIndex == 0) {
  94.         background = [UIImage imageNamed:@"cell_top.png"];
  95.     } else if (rowIndex == rowCount - 1) {
  96.         background = [UIImage imageNamed:@"cell_bottom.png"];
  97.     } else {
  98.         background = [UIImage imageNamed:@"cell_middle.png"];
  99.     }
  100.    
  101.     return background;
  102. }
  103.  
  104.  
  105. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  106. {
  107.     static NSString *CellIdentifier = @"Cell";
  108.     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  109.    
  110.     // Configure the cell...
  111.     if (cell == nil) {
  112.         cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  113.     }
  114.    
  115.     // Display recipe in the table cell
  116.     BMSetting *setting = [settingArray objectAtIndex:indexPath.row];
  117.    
  118.     UILabel *settingNameLabel = (UILabel *)[cell viewWithTag:101];
  119.     settingNameLabel.text = setting.name;
  120.    
  121.     // Assign our own background image for the cell
  122.     UIImage *background = [self cellBackgroundForRowAtIndexPath:indexPath];
  123.    
  124.     UIImageView *cellBackgroundView = [[UIImageView alloc] initWithImage:background];
  125.     cellBackgroundView.image = background;
  126.     cell.backgroundView = cellBackgroundView;
  127.    
  128.    
  129.     return cell;
  130. }
  131.  
  132.  
  133.  
  134. @end
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149. //  BMSetting.h
  150. //  IBcells
  151.  
  152.  
  153. #import <Foundation/Foundation.h>
  154.  
  155. @interface BMSetting : NSObject
  156.  
  157. @property (nonatomic, strong) NSString *name; // Name of setting
  158. @property (nonatomic, strong) NSString *detail; // Setting details
  159. @property (nonatomic, strong) NSString *setOn;  // Setting is set to On
  160. @property (nonatomic, strong) NSString *setOff;  // Setting is set to Off
  161. //@property (nonatomic, strong) IBOutlet UISwitch *settingSwitch;
  162. //@property (nonatomic, strong) NSString *imageFile; // image filename of recipe
  163.  
  164. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement