我的代码:
  1. #import "FirstViewController.h"
  2. @implementation FirstViewController
  3. @synthesize myHelpfile = ivHelpfile; //UIAlertView
  4. @synthesize myAboutfile = ivAboutfile; //UIAlertView
  5. @synthesize myNoarea = ivNoarea; //UIAlertView
  6. @synthesize myMap = ivMap; //UIImageView
  7. @synthesize myAreapick = ivAreapick; //UIActionSheet
  8. @synthesize myAdvancedmode = ivAdvancedmode; //NSString
  9. @synthesize myAreaset = ivAreaset; //NSString
  10. @synthesize myAreaarray = ivAreaarray; //NSArray
  11. @synthesize appSettingsViewController, settingsViewController;
  12. - (void)viewDidLoad {
  13.     [super viewDidLoad];
  14.     self.title = @"Wildlife";
  15.     NSString *area  = [[NSUserDefaults standardUserDefaults] stringForKey:@"mulValue"];
  16.     [self setMyAreaset:area];
  17.     if ([self myAreaset] == nil) { //check if any region is selected. If not, push UIActionsheet
  18.     NSArray *array = [[NSArray alloc] initWithObjects:      // creating array for different regions
  19.                        [NSString stringWithString:@"Region 1"],
  20.                        [NSString stringWithString:@"Region 2"],
  21.                        [NSString stringWithString:@"Region 3"],
  22.                        [NSString stringWithString:@"Region 4"],
  23.                        [NSString stringWithString:@"Region 5"],
  24.                        [NSString stringWithString:@"Region 6"],nil];
  25.     [self setMyAreaarray:array];
  26.     [array release], array = nil;      
  27.     NSLog(@"Built areaselectArray");
  28.     NSLog(@"Values of areaselectArray are %@",[self myAreaarray]);
  29.     UIActionSheet *areaselect = [[UIActionSheet alloc] initWithTitle:@"Select your current area" //creation of popup Area Selection
  30.                                                             delegate:self
  31.                                                    cancelButtonTitle:nil
  32.                                               destructiveButtonTitle:nil
  33.                                                    otherButtonTitles:nil];
  34.         [self setMyAreapick:areaselect];
  35.         [areaselect release], areaselect = nil;
  36.     int countarray = [[self myAreaarray] count];
  37.     for (int i = 0; i < countarray; i++) { //building list from array
  38.         [[self myAreapick] addButtonWithTitle:[[self myAreaarray] objectAtIndex:i]];
  39.     }
  40.     [[self myAreapick] addButtonWithTitle:@"Cancel"];
  41.     [self myAreapick].cancelButtonIndex = countarray;
  42.     [[self myAreapick] showInView:self.view];//show the general UIActionSheet instance
  43.     NSLog(@"Out of viewDidLoad");
  44.     }
  45.     else {
  46.         NSLog(@"Area is %@, no need for areaselectArray",area);
  47.         }   
  48. }
  49. -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger )buttonIndex
  50. {
  51.     int countarray = [[self myAreaarray] count];
  52.     if (buttonIndex != countarray) { //cancel button is at countarray, so for anything that is not cancel, do:
  53.             NSString *area = [[self myAreaarray] objectAtIndex:(buttonIndex)];
  54.             [self setMyAreaset:area];
  55.             [[NSUserDefaults standardUserDefaults] setObject:[self myAreaset] forKey:@"mulValue"];
  56.             [[NSUserDefaults standardUserDefaults] synchronize]; //sync
  57.             NSLog(@"Released areaselectArray");
  58.         }
  59.     else {
  60.     }
  61. }
复制代码
怎么回事呢?
初级工程师 2# xjliao 发表于 2012-2-23 11:48:50
  1. UIActionSheet *as = [[UIActionSheet alloc] initWithTitle:@"Test" delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
  2. for (int i = 0; i < 100; i++) {
  3.      [as addButtonWithTitle:[NSString stringWithFormat:@"Button %i", i]];
  4. }
  5. as.cancelButtonIndex = 99;
  6. as.destructiveButtonIndex = 0;
  7. [as showInView:self.view];
  8. [as release];
复制代码
版主 3# RealTool 发表于 2012-2-23 23:49:07
使用代码分析工具跑一下,查找就可以找到大部分 的内存泄露问题。
您需要登录后才可以回帖 登录 | 注册

关于我们|手机版|Archiver|DEVDIV.COM ( 京ICP备07040843号 )  

GMT+8, 2012-5-19 17:37

Powered by DEVDIV.COM!

© 2010-2012 DEVDIV.COM Coummunity.

回顶部