2012-07-30 71 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

相關問題