8-2作业的问题
在绘图的界面遇到问题, //数据调用 的部分总有报错,不知道怎么解决。如果把调用数据和绘图的部分都注释掉,是可以正常进如绘图的界面,
#import "graphicViewController.h"
@interface graphicViewController ()
@end
@implementation graphicViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIView * backgroundview=[[UIView alloc]initWithFrame:self.view.bounds];
backgroundview.backgroundColor=COLOR001;
[self.view addSubview:backgroundview];
//创建返回按钮
UIButton * returnbutton =[[UIButton alloc]initWithFrame:CGRectMake(self.view.bounds.size.width/2-40, self.view.bounds.size.height-70, 80, 40)];
returnbutton.backgroundColor=[UIColor colorWithRed:0.9 green:0.5 blue:0.3 alpha:1.0];
[returnbutton setTitle:@"返回" forState:UIControlStateNormal];
[returnbutton addTarget:self action:@selector(returnAction) forControlEvents:UIControlEventTouchDown];
[self.view addSubview:returnbutton];
//数据调用
NSMutableArray * array1=[self loadGraphicData];
NSMutableArray * array2 =[self parseGraphicData:array1];
// NSMutableArray * newData=[self nomarlizingData:array2];
////绘制图形
// Quartz * quartz =[[Quartz alloc]initWithFrame:self.view.bounds graphicData2:newData];
// [self.view addSubview:quartz];
// [quartz setNeedsDisplay];
}
//数据加载
-(NSMutableArray*)loadGraphicData{
NSString *filepath =[[NSBundle mainBundle]pathForResource:@"1" ofType:@"txt"];
NSData *data =[NSData dataWithContentsOfFile:filepath];
NSString * graphicdatastr=[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
NSMutableArray * array=[[NSMutableArray alloc]initWithArray:[graphicdatastr componentsSeparatedByString:@"\n"]];
return array;
}
//数据分析
-(NSMutableArray*)parseGraphicData:(NSMutableArray*)graphicData1{
NSMutableArray* graphicArray=[[NSMutableArray alloc]init];
//使用for循环,把每一个数据拿出来
for (int i=0;i<graphicData1.count;i++){
NSString *str=[graphicData1 objectAtIndex:i];
NSMutableArray * onegraphic =[[NSMutableArray alloc]initWithArray:[str componentsSeparatedByString:@" "]];
NSString * time1 = [onegraphic objectAtIndex:0];
NSString * level1 =[onegraphic objectAtIndex:1];
graphicData * onegraphicdata=[[graphicData alloc]init];
onegraphicdata.time=time1.floatValue;
onegraphicdata.waterlevel = level1.intValue;
[graphicArray addObject:onegraphicdata];
}
return graphicArray;
}
//数据归一化,把0-100的水位变成0-300之间的数字
-(NSMutableArray * )nomarlizingData:(NSMutableArray*)graphicData4{
NSMutableArray * newData=[[NSMutableArray alloc]init];
for(graphicData *item in graphicData4){
item.waterlevel = item.waterlevel*3;
[newData addObject:item];
}
return newData;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)returnAction{
[self dismissViewControllerAnimated:YES completion:nil];
}
@end
正在回答 回答被采纳积分+1
- 参与学习 1337 人
- 提交作业 712 份
- 解答问题 1878 个
很多人都在疑问没有基础该怎么学习iOS开发?不用担心,本路径采用游戏关卡式的教学模式,并且以经典OC与最新Swift双重结合的教学内容,帮助大家快速掌握两种iOS开发语言基础,去掉“零”标签。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星