Субъективный Си / Говнокод #19723 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //cell.textLabel.font = [UIFont fontWithName:@"Arial" size:10.0f];
    
    if([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row)
    {
        CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;
        if (iOSDeviceScreenSize.height < 568)
        {
            CGRect newFrame = tableView.frame;
            newFrame.size.height=iOSDeviceScreenSize.height;
            tableView.frame=newFrame;
        }
    }
}

Autolayout своими руками

bdevnameless bdevnameless, (Updated )

Комментарии (1, +1)

Субъективный Си / Говнокод #19580 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
+ (UIView *) createTextField:(NSString *)placeholder {
	UIView * view = [UIView new];
    view.frame = CGRectMake(0, 0, 100, 50);
    view.autoresizesSubviews = YES;
    view.backgroundColor = [UIColor whiteColor];
    view.layer.borderWidth = 0.5;
    view.layer.borderColor = COLOR(204, 204, 204).CGColor;
    view.layer.cornerRadius = 5;
    view.exclusiveTouch = YES;
    
    UITextField * testField = [UITextField new];
    testField.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    testField.textColor = [UIColor blackColor];
    testField.borderStyle = UITextBorderStyleNone;
    testField.autocorrectionType = UITextAutocorrectionTypeNo;
    [view addSubview:testField];

   return view;
}

Потом у нас есть какойто контроллер

- (void)viewDidLoad {
    [super viewDidLoad];

    textField = [[MyClass createTextField:@"CITY, STATE OR ZIP"] subviews][0];
    textField.returnKeyType = UIReturnKeySearch;
    textField.delegate = (id<UITextFieldDelegate>)self;
    [self.view addSubview:textField.superview];
}

На iOS 8.4 на устройстве текстфилд не будет отображаться
Нужно делать так:

UIView * v = [MyClass createTextField:@"CITY, STATE OR ZIP"];
textField = [v subviews][0];
[self.view addSubview:textField.superview];

COCOK-MAMOHTA COCOK-MAMOHTA, (Updated )

Комментарии (14, +14)

Субъективный Си / Говнокод #19412 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{  
  if (![_searchBarWhite.text isEqualToString:@""] || ![_searchBarBlue.text isEqualToString:@""]) {
        if (![[[LanguageList enumToString:[LanguageList indexOfItem:[[[[LanguageSelectDemon summon]getObjectAtIndex:indexPath.row]lastPathComponent]stringByDeletingPathExtension]]] lowercaseString] containsString:[[_searchBarWhite.text isEqualToString:@""]?_searchBarBlue.text:_searchBarWhite.text lowercaseString]]){
            return 0;}}}

начальство заставило писать функции макс на 4 строчки, и которые делают "одну вещи", вот итоги...

4oby 4oby, (Updated )

Комментарии (6, +6)

Субъективный Си / Говнокод #19347 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
NSError* utilitiesCheckEmail(NSString* string)
{
    NSInteger email_symbol_count=0;
    NSInteger pos_email_symbol=0;
    NSInteger pos_point=0;
    NSInteger count=string.length;

    
    if(count!=0)
    {
        unichar buffer[count];
    
        [string getCharacters:buffer];
        
        for(NSInteger i=0;i<count;i++)
        {
            unichar ch=buffer[i];
            
            if( !( (ch>='a') && (ch<='z') ) &&  !( (ch>='A') && (ch<='Z') ) && !( (ch>='0') && (ch<='9') ) && (ch!='_') && (ch!='-') )
            {
                switch (ch)
                {
                    case '@':
                    {
                        email_symbol_count++;
                        pos_email_symbol=i;
                        
                        break;
                    }
                        
                    case '.':
                    {
                        pos_point=i;
                        break;
                    }
                        
                    default:
                        return [NSError errorWithDomain:NULL error:eErrorEmailInvalidFormat];
                }
            }
        }
        
        if(  (email_symbol_count==1) && (pos_point!=0) && (pos_point>pos_email_symbol) && ((pos_point+1)<count) )
            return NULL;
    }
    
    return [NSError errorWithDomain:NULL error:eErrorEmailInvalidFormat];
}

Валидируем email

def def, (Updated )

Комментарии (9, +9)

Субъективный Си / Говнокод #19308 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
- (void) findFileTimeout: (NSTimer *) t {
    
    [detectFileTimerTimeout invalidate];
    detectFileTimerTimeout = nil;
    
    [detectFileTimer invalidate];
    detectFileTimer = nil;
    
    [WriteToLog WriteToLog:@"Timeout reached!"];
    [WriteToLog WriteToLog:@"Closing..."];
    
    exit(0);
    [NSApp terminate:nil];
    [[NSApplication sharedApplication] terminate:nil];
    
}

Выход по таймауту

EMax EMax, (Updated )

Комментарии (2, +2)

Субъективный Си / Говнокод #19159 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
- (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerLeftUtilityButtonWithIndex:(NSInteger)index
{
    switch (index) {
        case 0: STLog(@"left button 0 was pressed"); break;
        case 1: STLog(@"left button 1 was pressed"); break;
        case 2: STLog(@"left button 2 was pressed"); break;
        case 3: STLog(@"left btton 3 was pressed"); break;
        default: break;
    }
}

логируем кнопочки

Disconnecter1987 Disconnecter1987, (Updated )

Комментарии (139, +139)

Субъективный Си / Говнокод #19035 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
- (void)jumpToClass:(int)cIndex pageIndex:(int)pIndex {
  
    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

    //trick to store pIndex and cIndex
    int calc = cIndex*100;
    calc = calc + pIndex;
    indicator.tag = calc; //trick to store pIndex

    [self.view addSubview:indicator];
    [indicator bringSubviewToFront:self.view];
    [indicator startAnimating];
    
    [NSTimer scheduledTimerWithTimeInterval:0.01
                                     target:self
                                   selector:@selector(asyncJumpToClass:)
                                   userInfo:indicator
                                    repeats:NO];
    
}

- (void)asyncJumpToClass:(NSTimer*)theTimer {
    
    UIActivityIndicatorView *ind = (UIActivityIndicatorView *)[theTimer userInfo];
    int pIndex = ind.tag%100;
    int cIndex = ind.tag/100;

// еще 30 строк кода
}

Передача параметров

Headless Headless, (Updated )

Комментарии (9, +9)