2012-07-30 245 views
0

当我添加一个子视图时,它崩溃了我的应用程序。继承人会发生什么情况: 视图在另一个类中加载调用方法,然后该类在原始类中调用sortDataIntoSubs。然后,它试图添加一个子视图,但它崩溃,因为我相信它循环引起对象超出数组问题的代码。我该怎么办?添加一个视图到子视图崩溃我的应用程序

- (void)viewDidLoad 
{ 
searchText = [searchText uppercaseString]; 
self.title = searchText; 
Download_Data *dwnLD = [[Download_Data alloc]init]; 
NSDate *finishDate = [NSDate date]; 
NSDate *startDate = [NSDate date]; 
NSDateComponents *dayComponent = [[[NSDateComponents alloc] init] autorelease]; 
dayComponent.day = -1; 
NSCalendar *theCalendar = [NSCalendar currentCalendar]; 
startDate = [theCalendar dateByAddingComponents:dayComponent toDate:finishDate options:0]; 
[dwnLD downloadCSVFile:searchText startDate:startDate finishDate:finishDate key:1]; 
[super viewDidLoad]; 
} 


-(void) sortDataIntoSubs:(NSMutableArray *) arrMTemp 
{ 
NSMutableArray *arrDate = [[NSMutableArray alloc] init]; 
NSMutableArray *arrOpen = [[NSMutableArray alloc] init]; 
NSMutableArray *arrHigh = [[NSMutableArray alloc] init]; 
NSMutableArray *arrLow = [[NSMutableArray alloc] init]; 
NSMutableArray *arrClose = [[NSMutableArray alloc] init]; 
NSMutableArray *arrVolume = [[NSMutableArray alloc] init]; 
NSMutableArray *arrAdjClose = [[NSMutableArray alloc] init]; 
//Add every 7th object to the arrDate array. 

[self setUpView]; 
} 

-(void)setUpView 
{ 

CGRect screenBound = [[UIScreen mainScreen] bounds]; 
UISegmentedControl *segMeg = [[UISegmentedControl alloc]init]; 
segMeg.center = CGPointMake(screenBound.size.width/2,screenBound.size.height/2); 
segMeg.segmentedControlStyle = UISegmentedControlStylePlain; 
NSArray *arrSegMeg = [NSArray arrayWithObjects:@"1w",@"2w",@"8w",@"16w",@"25w", nil]; 
[segMeg initWithItems:arrSegMeg]; 
[self.view addSubview:segMeg]; //This crashes 

} 

视图由导航控制器处理。

+0

我刚刚这样做。 – JH95 2012-07-30 22:26:35

回答

1

您正在初始化segMeg两次。尝试像这样重新排列它,看看它是否有帮助:

CGRect screenBound = [[UIScreen mainScreen] bounds]; 
NSArray *arrSegMeg = [NSArray arrayWithObjects:@"1w",@"2w",@"8w",@"16w",@"25w", nil]; 
UISegmentedControl *segMeg = [[UISegmentedControl alloc] initWithItems:arrSegMeg]; 
segMeg.center = CGPointMake(screenBound.size.width/2,screenBound.size.height/2); 
segMeg.segmentedControlStyle = UISegmentedControlStylePlain; 
[self.view addSubview:segMeg]; 
+0

谢谢但不,仍然崩溃。 – JH95 2012-08-01 13:09:46

相关问题