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

답변

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

관련 문제