当我添加子视图时,它会使我的应用程序崩溃。下面是发生的情况: View 确实加载调用了另一个类中的方法,然后该类调用了原始类中的 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
}
视图由导航控制器处理。