2012-03-06 1 views
1

NSMutableURLRequest을 사용하는 서버에서 .CSV 파일을 읽었으며 CSV 구문 분석을 수행 할 때 불완전한 플로팅 포인트를 읽게됩니다. 예를 들어, 300 plus 행이있는 경우 앱은 150 번째 더하기 행에서 읽습니다. 이 접근 방법에 대한 제안? 플롯 포인트의 값을 저장하는 함수가 있습니까? 죄송합니다. iOS를 처음 사용합니다.NSMutableURLRequest의 CSV 구문 분석에서 첫 번째 150 개의 행이 누락됩니다.

- (id) init 
{ 
// regular [super init], etc. etc. 
    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(_connectionTimer:) userInfo:nil repeats:YES]; 
// other custom initialization continues 
    return self; 
} 

-(void)serverConnect{ 
      NSMutableURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"URL/test.csv"] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:15.0]; 

      NSURLConnection *connection= [[NSURLConnection alloc] initWithRequest:request delegate:self]; 

     } 


- (void) _connectionTimer:(NSTimer *)timer { 
      [self serverConnect]; 
     } 

-(void)connection :(NSURLConnection *) connection didReceiveData:(NSData *)data{ 
     response = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 
    } 

- (void)connectionDidFinishLoading:(NSURLConnection *)connection { 


     NSString *stripped1 = [response stringByReplacingOccurrencesOfString:@"\r" withString:@""]; 

     NSMutableArray *rows = [NSMutableArray arrayWithArray:[stripped1 componentsSeparatedByString:@"\n"]]; 
     NSMutableArray *contentArray = [NSMutableArray arrayWithCapacity:[rows count]]; 
     NSMutableArray *contentArray1 = [NSMutableArray arrayWithCapacity:[rows count]]; 
     NSArray *components; 

     for (int i=0;i<[rows count]; i++) { 

      if(i == 0 || [[rows objectAtIndex:i] isEqualToString:@""]){ 
      continue; 
      } 
      components = [[rows objectAtIndex:i] componentsSeparatedByString:@","]; 

     id x = [components objectAtIndex:0] ; 
     id y = [components objectAtIndex:1]; 
     id z = [components objectAtIndex:2]; 

     [contentArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:x,@"X",y,@"Y", nil]]; 
     [contentArray1 addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:x,@"X",z,@"Y", nil]]; 
    } 

} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    [_graphHostingView setContentSize:CGSizeMake(2000, 1000)]; 
    _graphHostingView.scrollEnabled = YES; 
    _graphHostingView.showsHorizontalScrollIndicator = YES; 
    _graphHostingView.showsVerticalScrollIndicator = YES; 



    [self init]; 
    //[self serverConnect]; 

} 

변수 응답이 NSString 인 도움을 많이 주셔서 감사합니다. MSMutableString 또는 NSMutableArray을 사용하면 더 좋을까요? 아무도 어떻게 -(NSArray *)numbersForPlot:(CPPlot *)plot field:(NSUInteger)fieldEnum recordIndexRange:(NSRange)indexRange; 방법이 도움이되는지 설명 할 수 있습니까? 플롯 데이터를 저장하는 데 도움이됩니까? 다음으로 코어 플롯을 사용하여 플롯을 작성하면로드 할 수 있습니까? 타이머를 사용하여 읽는 데이터에 영향을 줍니까?

답변

0

서버에서 데이터를 가져 오는 데 사용하는 메서드가 아니라 stringWithContentsOfURL을 사용하려고합니다. 나는 그것이 문제가 발생하는 곳이라고 가정하고, 최종 목표는 모든 데이터를 문자열로 가져와 어쨌든 그렇게하는 것이 더 효율적인 방법이 될 것이라고 생각합니다.

관련 문제