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

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
- (UIImage*)thumbnailImage:(NSString*)fileName:(BOOL)includeInCache
{
	NSString *extension=@"png";
	
	if(hasRetinaDisplay)
	{
		NSString *newFileName=[fileName stringByAppendingString:@"@2x"];
		newFileName=[newFileName stringByAppendingFormat:@".%@", extension];
		
		BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] resourcePath], newFileName]];
		
		if(fileExists)
			fileName=[fileName stringByAppendingString:@"@2x"];
	}
	
	fileName=[fileName stringByAppendingFormat:@".%@", extension]; 
	
	UIImage *thumbnail = nil;
	
	if(includeInCache)
		thumbnail=[thumbnailCache objectForKey:fileName];
	
	if (thumbnail == nil)
	{
		NSString *thumbnailFile = [NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] resourcePath], fileName];
		
		BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:thumbnailFile];
		
		if(fileExists)
		{
			thumbnail = [UIImage imageWithContentsOfFile:thumbnailFile];
			
			if(includeInCache)
				[thumbnailCache setObject:thumbnail forKey:fileName];
		}
	}
						  
	return thumbnail;
}

велосипедище

diduz diduz, (Updated )

Комментарии (0)

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

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
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
  72. 72
  73. 73
  74. 74
  75. 75
  76. 76
  77. 77
  78. 78
  79. 79
  80. 80
  81. 81
  82. 82
  83. 83
  84. 84
  85. 85
  86. 86
  87. 87
  88. 88
  89. 89
  90. 90
  91. 91
  92. 92
  93. 93
  94. 94
  95. 95
  96. 96
  97. 97
  98. 98
  99. 99
#define EmptyText @""
#define TextZero @"0"
#define TextOne @"1"
#define TextTwo @"2"
#define TextThree @"3"
#define TextFour @"4"
#define TextFive @"5"
#define TextSix @"6"
#define TextSeven @"7"
#define TextEight @"8"
#define TextNine @"9"

#define DigitZero 0
#define DigitOne 1
#define DigitTwo 2
#define DigitThree 3
#define DigitFour 4
#define DigitFive 5
#define DigitSix 6
#define DigitSeven 7
#define DigitEight 8
#define DigitNine 9

-(IBAction)DigitButtonClicked:(id)sender {
    UIButton *button = (UIButton *)sender;
    if ([digitLabel.text isEqualToString:TextZero]) {
        if (button.tag == DigitOne) {
            digitLabel.text = TextOne;
        }
        if (button.tag == DigitTwo) {
            digitLabel.text = TextTwo;
        }
        if (button.tag == DigitThree) {
            digitLabel.text = TextThree;
        }
        if (button.tag == DigitFour) {
            digitLabel.text = TextFour;
        }
        if (button.tag == DigitFive) {
            digitLabel.text = TextFive;
        }
        if (button.tag == DigitSix) {
            digitLabel.text = TextSix;
        }
        if (button.tag == DigitSeven) {
            digitLabel.text = TextSeven;
        }
        if (button.tag == DigitEight) {
            digitLabel.text = TextEight;
        }
        if (button.tag == DigitNine) {
            digitLabel.text = TextNine;
        }
    } else {
        if (button.tag == DigitOne) {
            digitLabel.text = [digitLabel.text stringByAppendingFormat:@"%d",DigitOne];
        }
        if (button.tag == DigitTwo) {
            digitLabel.text = [digitLabel.text stringByAppendingFormat:@"%d",DigitTwo];
        }
        if (button.tag == DigitThree) {
            digitLabel.text = [digitLabel.text stringByAppendingFormat:@"%d",DigitThree];
        }
        if (button.tag == DigitFour) {
            digitLabel.text = [digitLabel.text stringByAppendingFormat:@"%d",DigitFour];
        }
        if (button.tag == DigitFive) {
            digitLabel.text = [digitLabel.text stringByAppendingFormat:@"%d",DigitFive];
        }
        if (button.tag == DigitSix) {
            digitLabel.text = [digitLabel.text stringByAppendingFormat:@"%d",DigitSix];
        }
        if (button.tag == DigitSeven) {
            digitLabel.text = [digitLabel.text stringByAppendingFormat:@"%d",DigitSeven];
        }
        if (button.tag == DigitEight) {
            digitLabel.text = [digitLabel.text stringByAppendingFormat:@"%d",DigitEight];
        }
        if (button.tag == DigitNine) {
            digitLabel.text = [digitLabel.text stringByAppendingFormat:@"%d",DigitNine];
        }
        if (button.tag == DigitZero) {
            digitLabel.text = [digitLabel.text stringByAppendingFormat:@"%d",DigitZero];
        }
    }
}

-(IBAction)DeleteButtonClicked {
    if (![digitLabel.text isEqualToString:TextZero]) {
        if (![digitLabel.text isEqualToString:EmptyText]) {
            digitLabel.text = [ digitLabel.text substringToIndex:[digitLabel.text length] - 1 ];
            if ([digitLabel.text length] == DigitZero) {
                digitLabel.text = TextZero;
            }
        } else {
            digitLabel.text = TextZero;
        }
    }
}

кусок кода, который по нажатой кнопке определяет что за цифра и добавляет ее в конец строки (или удаляет)...
контрол по типу калькулятора

olgerd olgerd, (Updated )

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

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

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
if( (ori == UIInterfaceOrientationLandscapeLeft) || (ori == UIInterfaceOrientationLandscapeRight))
{
    // Some code
}
else if(ori==UIInterfaceOrientationPortrait || ori==UIInterfaceOrientationPortraitUpsideDown)
{
    // Some other code
}
else {
    // God mode on!
}

Реальный проект после индусов... Что движет этими людьми я не понимаю...

makadaw makadaw, (Updated )

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

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

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
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
  72. 72
  73. 73
  74. 74
  75. 75
  76. 76
  77. 77
  78. 78
  79. 79
  80. 80
  81. 81
  82. 82
  83. 83
  84. 84
  85. 85
  86. 86
  87. 87
  88. 88
  89. 89
  90. 90
  91. 91
  92. 92
  93. 93
  94. 94
  95. 95
  96. 96
  97. 97
  98. 98
NetworkStatus internet = [internetReachable currentReachabilityStatus];

switch (internet)
{
    case NotReachable:		{ internetStatus = NO;  break; }
    case ReachableViaWiFi:	{ internetStatus = YES; break; }
    case ReachableViaWWAN:	{ internetStatus = YES; break; }
    default: break;
}

NetworkStatus host = [hostReachable currentReachabilityStatus];
switch (host)
{
    case NotReachable:		{ hostStatus = NO;  break; }
    case ReachableViaWiFi:	{ hostStatus = YES; break; }
    case ReachableViaWWAN:	{ hostStatus = YES; break; }
    default: break;
}

//-------------------------------------------------------------

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { 
	return false; 
}

//-------------------------------------------------------------

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
	if (logicRotate == 1)
	{
		if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) // если ЛандскейпРайт
		{
			FlowCover.transform = CGAffineTransformIdentity;
			indexLandscape = 1;
		}
		if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) // если ЛандскейпЛефт
		{
			FlowCover.transform = CGAffineTransformMakeRotation(M_PI);
			indexLandscape = 0;
		}
	}
	else
	{
		if (indexLandscape == 1)
		{
			FlowCover.transform = CGAffineTransformIdentity;
		}
		else
		{
			FlowCover.transform = CGAffineTransformMakeRotation(M_PI);
		}
		logicRotate = 1;
	}
	return false;
}

//-------------------------------------------------------------

pagetextLabel.hidden = (pageFullScreen.realPageNo) ? NO : YES;

//-------------------------------------------------------------

[(FastImageView*)page showImage:[listOfImages objectAtIndex:pageIndex]]; //картинка

//-------------------------------------------------------------

if (firstPages>2) {
    ...
    if (theAudio) {
        [theAudio play];	//звук
    }
    firstPages++;
}
else
{
    firstPages++;
}

//-------------------------------------------------------------

LabPercent.text = [NSString stringWithFormat:@"%d%@", percent * 100, @"%"];

//-------------------------------------------------------------

if ([DELEGATE isIPad]) {
    mTempSize = [tempstr sizeWithFont:[UIFont fontWithName:@"Helvetica" size:17.0f] constrainedToSize:maxSize lineBreakMode:UILineBreakModeTailTruncation];
}
else {
    mTempSize = [tempstr sizeWithFont:[UIFont fontWithName:@"Helvetica" size:12.0f] constrainedToSize:maxSize lineBreakMode:UILineBreakModeTailTruncation];
}
h = mTempSize.height;
if ([DELEGATE isIPad]) {
    lab.font = [UIFont fontWithName:@"Helvetica" size:17.0f];
}
else {
    lab.font = [UIFont fontWithName:@"Helvetica" size:12.0f];
}

От того же автора http://govnokod.ru/6964. Тут избранные куски, хотя можно постить весь проект

GLvRzZZ GLvRzZZ, (Updated )

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

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

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
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
+ (NSUInteger)tagExpensiveCandyAnimationInteger:(NSUInteger)tagSprite
{
	NSUInteger animationTag;
	if(tagSprite == 2001)
	{
		animationTag = 2101;
	}
	else if(tagSprite == 2002)
	{
		animationTag = 2102;
	}	
	else if(tagSprite == 2003)
	{
		animationTag = 2103;
	}		
	else if(tagSprite == 2004)
	{
		animationTag = 2104;
	}		
	else if(tagSprite == 2005)
	{
		animationTag = 2105;
	}		
	else if(tagSprite == 2006)
	{
		animationTag = 2106;
	}		
	else if(tagSprite == 2007)
	{
		animationTag = 2107;
	}			
	else if(tagSprite == 2008)
	{
		animationTag = 2108;
	}
	else if(tagSprite == 2009)
	{
		animationTag = 2109;
	}	
	else if(tagSprite == 2010)
	{
		animationTag = 2110;
	}		
	else if(tagSprite == 2011)
	{
		animationTag = 2111;
	}		
	else if(tagSprite == 2012)
	{
		animationTag = 2112;
	}			
	
	return animationTag;
}

Того же автора:)

Chippman Chippman, (Updated )

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

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

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
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
	if (rotateBag > 6) //после возврата, шудавторотейт вызывается 7 раз, это условие для погашения этих вызовов
	{
		if ([portret isEqualToString:@"horizontal"])
		{
			if (firstLaunch == 0) //  блок для первого запуска (по умолчанию всегда выставляет ландскейпРайт, а это не всегда правильно)
			{
				if (interfacePosition == 0)
					{ self.view.transform = CGAffineTransformMakeRotation(M_PI); }
				else
					{ self.view.transform = CGAffineTransformIdentity; }
				firstLaunch++;
				indexLandscape = interfacePosition;
			}
			else
			{
				if (indexLandscape == 1)	//если изначальный вариант был правосторонний
				{
					if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) // если ЛандскейпРайт
						{ self.view.transform = CGAffineTransformIdentity;
						  interfacePosition = 1; }
					if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)	// если ЛандскейпЛефт
							{ self.view.transform = CGAffineTransformMakeRotation(M_PI);
							  interfacePosition = 0; }
				}
				else				//если изначальный вариант был левосторонний
				{
					if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) // если ЛандскейпРайт
						{ self.view.transform = CGAffineTransformMakeRotation(M_PI);
						  interfacePosition = 1; }
					if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)	// если ЛандскейпЛефт
						{ self.view.transform = CGAffineTransformIdentity;
						  interfacePosition = 0; }
				}
			}
		}
		else
		{
			if (firstLaunch == 0) //  блок для первого запуска (по умолчанию показывается правильно, поэтому ничего делать не надо)
				{ firstLaunch++; }
			else
			{
				if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
					{ self.view.transform = CGAffineTransformIdentity; }
				if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
					{ self.view.transform = CGAffineTransformMakeRotation(M_PI); }
			}
		}
	}
	else { 
		rotateBag++; 
	}
	return false;
}

Крутящаяся сумка в действии...
Поворот дисплея в 50 строк :\

mrWindMak3r mrWindMak3r, (Updated )

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

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

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
if (starsCounter == 1) 
	{
		[DCObjects drawSpriteFromBatch:bg name:@"star-little.png" point:ccp(250, 190) z:1 tag:1];	
	}
	else if (starsCounter == 2) 
	{
		[DCObjects drawSpriteFromBatch:bg name:@"star-little.png" point:ccp(250, 190) z:1 tag:1];
		[DCObjects drawSpriteFromBatch:bg name:@"star-little.png" point:ccp(260, 190) z:1 tag:1];
	}
	else if (starsCounter == 3) 
	{
		[DCObjects drawSpriteFromBatch:bg name:@"star-little.png" point:ccp(250, 190) z:1 tag:1];
		[DCObjects drawSpriteFromBatch:bg name:@"star-little.png" point:ccp(260, 190) z:1 tag:1];
		[DCObjects drawSpriteFromBatch:bg name:@"star-little.png" point:ccp(270, 190) z:1 tag:1];
	}
	else if (starsCounter == 4) 
	{
		[DCObjects drawSpriteFromBatch:bg name:@"star-little.png" point:ccp(250, 190) z:1 tag:1];
		[DCObjects drawSpriteFromBatch:bg name:@"star-little.png" point:ccp(260, 190) z:1 tag:1];
		[DCObjects drawSpriteFromBatch:bg name:@"star-little.png" point:ccp(270, 190) z:1 tag:1];
		[DCObjects drawSpriteFromBatch:bg name:@"star-little.png" point:ccp(280, 190) z:1 tag:1];
	}
	else if (starsCounter == 5) 
	{
		[DCObjects drawSpriteFromBatch:bg name:@"star-little.png" point:ccp(250, 190) z:1 tag:1];
		[DCObjects drawSpriteFromBatch:bg name:@"star-little.png" point:ccp(260, 190) z:1 tag:1];
		[DCObjects drawSpriteFromBatch:bg name:@"star-little.png" point:ccp(270, 190) z:1 tag:1];
		[DCObjects drawSpriteFromBatch:bg name:@"star-little.png" point:ccp(280, 190) z:1 tag:1];
		[DCObjects drawSpriteFromBatch:bg name:@"star-little.png" point:ccp(290, 190) z:1 tag:1];
	}

Chippman Chippman, (Updated )

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

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

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
-(BOOL) checkIsDeleted:(Transactions*)target
{
    if (target.transactionType == TransactionTypeTransfer)
    {
        if (target.cashFlow && target.cashFlow.isDeleted && target.secondCashFlow && target.secondCashFlow.isDeleted)
            return YES;
        return NO;
    }
    else
        if (target.cashFlow && target.cashFlow.isDeleted)
            return YES;
    return NO;
}

Классика )))

Tika-Z Tika-Z, (Updated )

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

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

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
/ set view controller
// this is just a pointer to object2
object1 = object2;

// claim ownership from object2
[object1 retain];
[object2 release];

This is all that is required. I have already tested & it works.

Пишем iPhone проект, боремся с мемори ликом, разработчик из индии (не учавствует в проекте) предлагает выход из положения с "вротмненоги" знанием дела

leon_coder leon_coder, (Updated )

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