向子视图添加视图会导致我的应用程序崩溃

时间:2012-07-30 22:23:55

标签: objective-c uiview crash subview

当我添加子视图时,它会崩溃我的应用程序。继承人会发生什么: 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

}

视图由导航控制器处理。

1 个答案:

答案 0 :(得分: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];