gpt4 book ai didi

objective-c - 将 View 添加到 subview 会使我的应用程序崩溃

转载 作者:行者123 更新时间:2023-12-03 16:55:21 25 4
gpt4 key购买 nike

当我添加一个 subview 时,它会使我的应用程序崩溃。继承人发生了什么:
View确实加载了另一个类中的方法,然后该类在原始类中调用sortDataIntoSubs。然后尝试添加一个 subview ,但是由于我认为它循环了代码而导致对象超出数组问题,因此它崩溃了。我该怎么办?

 - (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

}

该 View 由导航 Controller 处理。

最佳答案

您要初始化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];

关于objective-c - 将 View 添加到 subview 会使我的应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11730576/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com