Advertisement
Scott_Rowley

UIButton in UITableViewCell

Sep 19th, 2014
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  2.  
  3. if ([tableView isEqual:[self HoursTableView]]){
  4.        
  5.         NSString *timeText = [arrayOfHours objectAtIndex:indexPath.row];
  6.        
  7.         NSString *apptHour = [timeText substringToIndex:2];
  8.         NSString *apptMins = [timeText substringFromIndex:2];
  9.  
  10.         UITableViewCell *cell  = [tableView dequeueReusableCellWithIdentifier:@"SCHEDULE_ROW"];
  11.        
  12.         NSDateFormatter *DateFormatter=[[NSDateFormatter alloc] init];
  13.         [DateFormatter setDateFormat:[NSString stringWithFormat:@"%@-%@-%@-%@-%@",TODAY_year, TODAY_month, TODAY_day, apptHour, apptMins]];
  14.        
  15.         NSString *TODAY = [DateFormatter stringFromDate:[NSDate date]];
  16.        
  17.         int BEGIN_THIS_HOUR_EPOCH = [[self toEpoch:TODAY] intValue];
  18.         int END_THIS_HOUR_EPOCH = BEGIN_THIS_HOUR_EPOCH + 3600;
  19.        
  20.         // Get items
  21.         sqlite3_stmt *statementSCHEDULE;
  22.            
  23.         NSString *querySQL = [NSString stringWithFormat:@"SELECT APS.DATE_TIME_START, APS.DATE_TIME_END, APS.APPT_ID, APS.HOURS, CONTACT_NAME, CONTACT_LASTNAME, APS.ARTIST_ID FROM APPOINTMENTS APS LEFT JOIN CONTACTS ON CONTACTS.CONTACT_ID=APS.CONTACT_ID WHERE (DATE_TIME_START>='%i' AND DATE_TIME_START<='%i') ORDER BY APS.ARTIST_ID", BEGIN_THIS_HOUR_EPOCH, END_THIS_HOUR_EPOCH];
  24.        
  25.         //NSLog(@"Query: %@",querySQL);
  26.        
  27.         const char* query_sql = [querySQL UTF8String];
  28.        
  29.         UILabel *time = (UILabel *)[cell viewWithTag:655];
  30.  
  31.         UILabel *sched_time_a1  = (UILabel *)[cell viewWithTag:101];
  32.         UILabel *sched_time_a2  = (UILabel *)[cell viewWithTag:102];
  33.         UILabel *sched_time_a3  = (UILabel *)[cell viewWithTag:103];
  34.         UILabel *sched_time_a4  = (UILabel *)[cell viewWithTag:104];
  35.         UILabel *sched_time_a5  = (UILabel *)[cell viewWithTag:105];
  36.         UILabel *sched_time_a6  = (UILabel *)[cell viewWithTag:106];
  37.         UILabel *sched_time_a7  = (UILabel *)[cell viewWithTag:107];
  38.         UILabel *sched_time_a8  = (UILabel *)[cell viewWithTag:108];
  39.        
  40.         //UIView *sched_a1       = (UIView *)[cell viewWithTag:111];
  41.         UIView *sched_a2       = (UIView *)[cell viewWithTag:112];
  42.         UIView *sched_a3       = (UIView *)[cell viewWithTag:113];
  43.         UIView *sched_a4       = (UIView *)[cell viewWithTag:114];
  44.         UIView *sched_a5       = (UIView *)[cell viewWithTag:115];
  45.         UIView *sched_a6       = (UIView *)[cell viewWithTag:116];
  46.         UIView *sched_a7       = (UIView *)[cell viewWithTag:117];
  47.         UIView *sched_a8       = (UIView *)[cell viewWithTag:118];
  48.        
  49.         UILabel *sched_name_a1  = (UILabel *)[cell viewWithTag:121];
  50.         UILabel *sched_name_a2  = (UILabel *)[cell viewWithTag:122];
  51.         UILabel *sched_name_a3  = (UILabel *)[cell viewWithTag:123];
  52.         UILabel *sched_name_a4  = (UILabel *)[cell viewWithTag:124];
  53.         UILabel *sched_name_a5  = (UILabel *)[cell viewWithTag:125];
  54.         UILabel *sched_name_a6  = (UILabel *)[cell viewWithTag:126];
  55.         UILabel *sched_name_a7  = (UILabel *)[cell viewWithTag:127];
  56.         UILabel *sched_name_a8  = (UILabel *)[cell viewWithTag:128];
  57.  
  58.         sched_name_a1.text = @"";
  59.         sched_name_a2.text = @"";
  60.         sched_name_a3.text = @"";
  61.         sched_name_a4.text = @"";
  62.         sched_name_a5.text = @"";
  63.         sched_name_a6.text = @"";
  64.         sched_name_a7.text = @"";
  65.         sched_name_a8.text = @"";
  66.        
  67.         sched_time_a1.text = @"";
  68.         sched_time_a2.text = @"";
  69.         sched_time_a3.text = @"";
  70.         sched_time_a4.text = @"";
  71.         sched_time_a5.text = @"";
  72.         sched_time_a6.text = @"";
  73.         sched_time_a7.text = @"";
  74.         sched_time_a8.text = @"";
  75.        
  76.         sched_a2.layer.backgroundColor = [UIColor clearColor].CGColor;
  77.         sched_a3.layer.backgroundColor = [UIColor clearColor].CGColor;
  78.         sched_a4.layer.backgroundColor = [UIColor clearColor].CGColor;
  79.         sched_a5.layer.backgroundColor = [UIColor clearColor].CGColor;
  80.         sched_a6.layer.backgroundColor = [UIColor clearColor].CGColor;
  81.         sched_a7.layer.backgroundColor = [UIColor clearColor].CGColor;
  82.         sched_a8.layer.backgroundColor = [UIColor clearColor].CGColor;
  83.        
  84.         sched_a2.layer.borderWidth = 0;
  85.         sched_a3.layer.borderWidth = 0;
  86.         sched_a4.layer.borderWidth = 0;
  87.         sched_a5.layer.borderWidth = 0;
  88.         sched_a6.layer.borderWidth = 0;
  89.         sched_a7.layer.borderWidth = 0;
  90.         sched_a8.layer.borderWidth = 0;
  91.        
  92.         if (sqlite3_open([dbPathString UTF8String], &inkStudiosDB)==SQLITE_OK) {
  93.         if(sqlite3_prepare(inkStudiosDB, query_sql, -1, &statementSCHEDULE, NULL)==SQLITE_OK) {
  94.            
  95.             while (sqlite3_step(statementSCHEDULE)==SQLITE_ROW) {
  96.                
  97.                 NSString *start = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statementSCHEDULE, 0)];
  98.                 NSString *end = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statementSCHEDULE, 1)];
  99.                 NSString *APPT_ID = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statementSCHEDULE, 2)];
  100.                 int Hours = sqlite3_column_int(statementSCHEDULE, 3);
  101.                 NSString *FIRST = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statementSCHEDULE, 4)];
  102.                 NSString *ID = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statementSCHEDULE, 6)];
  103.                 NSString *START = [self fromEpochToHuman:start withFormat:@"ha"];
  104.                 NSString *END = [self fromEpochToHuman:end withFormat:@"ha"];
  105.                 int heightCalc = Hours * 52;
  106.                
  107.                 UIButton *sched_button_a1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  108.  
  109.                
  110.                 if ([ID isEqualToString:artist_one]) {
  111.                    
  112.                     sched_name_a1.text = FIRST;
  113.                     sched_time_a1.text = [NSString stringWithFormat:@"%@ - %@", START, END];
  114.  
  115.                    
  116.                    
  117.                    
  118.                     sched_button_a1.frame = CGRectMake(73, 0, 110, 52);
  119.                     CGRect frame_a1 = sched_button_a1.frame;
  120.                    
  121.                     // Resize height based on length of appointment
  122.                     frame_a1.size.height = heightCalc;
  123.                     sched_button_a1.frame = frame_a1;
  124.                     [sched_button_a1 setTitle:APPT_ID forState:UIControlStateNormal];
  125.                     sched_button_a1.layer.backgroundColor = [[UIColor greenColor] colorWithAlphaComponent:0.4f].CGColor;
  126.                    
  127.                     [sched_button_a1 addTarget:self action:@selector(showAppointment:) forControlEvents:UIControlEventTouchUpInside];
  128.                     [cell.contentView addSubview:sched_button_a1];
  129.                     [cell.contentView bringSubviewToFront:sched_button_a1];
  130.  
  131.                    
  132.                 }else if([ID isEqualToString:artist_two]){
  133.                    
  134.                     CGRect frame = sched_a2.frame;
  135.                     frame.size.height = heightCalc;
  136.                     sched_a2.frame = frame;
  137.                     sched_a2.layer.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.4f].CGColor;
  138.                     sched_name_a2.text = FIRST;
  139.                     sched_time_a2.text = [NSString stringWithFormat:@"%@ - %@", START, END];
  140.                     sched_a2.layer.borderColor = [UIColor whiteColor].CGColor;
  141.                     sched_a2.layer.borderWidth = 1;
  142.                     [sched_a2.layer setCornerRadius:8.0f];
  143.                     [sched_a2.layer setMasksToBounds:YES];
  144.                    
  145.                 }else if([ID isEqualToString:artist_three]){
  146.                    
  147.                     CGRect frame = sched_a3.frame;
  148.                     frame.size.height = heightCalc;
  149.                     sched_a3.frame = frame;
  150.                     sched_a3.layer.backgroundColor = [[UIColor colorWithRed:204.0f/255.0f green:32.0f/255.0f blue:32.0f/255.0f alpha:1.0] colorWithAlphaComponent:0.4f].CGColor;
  151.                     sched_name_a3.text = FIRST;
  152.                     sched_time_a3.text = [NSString stringWithFormat:@"%@ - %@", START, END];
  153.                     sched_a3.layer.borderColor = [UIColor whiteColor].CGColor;
  154.                     sched_a3.layer.borderWidth = 1;
  155.                     [sched_a3.layer setCornerRadius:8.0f];
  156.                     [sched_a3.layer setMasksToBounds:YES];
  157.                    
  158.                 }else if([ID isEqualToString:artist_four]){
  159.                    
  160.                     CGRect frame = sched_a4.frame;
  161.                     frame.size.height = heightCalc;
  162.                     sched_a4.frame = frame;
  163.                     sched_a4.layer.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.4f].CGColor;
  164.                     sched_name_a4.text = FIRST;
  165.                     sched_time_a4.text = [NSString stringWithFormat:@"%@ - %@", START, END];
  166.                     sched_a4.layer.borderColor = [UIColor whiteColor].CGColor;
  167.                     sched_a4.layer.borderWidth = 1;
  168.                     [sched_a4.layer setCornerRadius:8.0f];
  169.                     [sched_a4.layer setMasksToBounds:YES];
  170.                    
  171.                 }else if([ID isEqualToString:artist_five]){
  172.                    
  173.                     CGRect frame = sched_a5.frame;
  174.                     frame.size.height = heightCalc;
  175.                     sched_a5.frame = frame;
  176.                     sched_a5.layer.backgroundColor = [[UIColor colorWithRed:204.0f/255.0f green:32.0f/255.0f blue:32.0f/255.0f alpha:1.0] colorWithAlphaComponent:0.4f].CGColor;
  177.                     sched_name_a5.text = FIRST;
  178.                     sched_time_a5.text = [NSString stringWithFormat:@"%@ - %@", START, END];
  179.                     sched_a5.layer.borderColor = [UIColor whiteColor].CGColor;
  180.                     sched_a5.layer.borderWidth = 1;
  181.                     [sched_a5.layer setCornerRadius:8.0f];
  182.                     [sched_a5.layer setMasksToBounds:YES];
  183.                    
  184.                 }else if([ID isEqualToString:artist_six]){
  185.                    
  186.                     CGRect frame = sched_a6.frame;
  187.                     frame.size.height = heightCalc;
  188.                     sched_a6.frame = frame;
  189.                     sched_a6.layer.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.4f].CGColor;
  190.                     sched_name_a6.text = FIRST;
  191.                     sched_time_a6.text = [NSString stringWithFormat:@"%@ - %@", START, END];
  192.                     sched_a6.layer.borderColor = [UIColor whiteColor].CGColor;
  193.                     sched_a6.layer.borderWidth = 1;
  194.                     [sched_a6.layer setCornerRadius:8.0f];
  195.                     [sched_a6.layer setMasksToBounds:YES];
  196.                    
  197.                 }else if([ID isEqualToString:artist_seven]){
  198.                    
  199.                     CGRect frame = sched_a7.frame;
  200.                     frame.size.height = heightCalc;
  201.                     sched_a7.frame = frame;
  202.                     sched_a7.layer.backgroundColor = [[UIColor colorWithRed:204.0f/255.0f green:32.0f/255.0f blue:32.0f/255.0f alpha:1.0] colorWithAlphaComponent:0.4f].CGColor;
  203.                     sched_name_a7.text = FIRST;
  204.                     sched_time_a7.text = [NSString stringWithFormat:@"%@ - %@", START, END];
  205.                     sched_a7.layer.borderColor = [UIColor whiteColor].CGColor;
  206.                     sched_a7.layer.borderWidth = 1;
  207.                     [sched_a7.layer setCornerRadius:8.0f];
  208.                     [sched_a7.layer setMasksToBounds:YES];
  209.                    
  210.                 }else if([ID isEqualToString:artist_eight]){
  211.                    
  212.                     CGRect frame = sched_a8.frame;
  213.                     frame.size.height = heightCalc;
  214.                     sched_a8.frame = frame;
  215.                     sched_a8.layer.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.4f].CGColor;
  216.                     sched_name_a8.text = FIRST;
  217.                     sched_time_a8.text = [NSString stringWithFormat:@"%@ - %@", START, END];
  218.                     sched_a8.layer.borderColor = [UIColor whiteColor].CGColor;
  219.                     sched_a8.layer.borderWidth = 1;
  220.                     [sched_a8.layer setCornerRadius:8.0f];
  221.                     [sched_a8.layer setMasksToBounds:YES];
  222.                    
  223.                 }
  224.                
  225.             }
  226.             sqlite3_close(inkStudiosDB);
  227.  
  228.         }else{
  229.             NSLog(@"Error fetching appointments (inner): %s", sqlite3_errmsg(inkStudiosDB));
  230.             sqlite3_close(inkStudiosDB);
  231.         }
  232.             sqlite3_close(inkStudiosDB);
  233.         }else{NSLog(@"Error fetching appointments (outter): %s", sqlite3_errmsg(inkStudiosDB));}
  234.        
  235.        
  236.         time.text = timeText;
  237.  
  238.         [self HoursTableView].backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4f];
  239.         cell.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.0f];
  240.  
  241.  
  242.        
  243.         return cell;
  244.        
  245.     }
  246.  
  247.     return nil;
  248. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement