Import csv data (SDK iphone)

后端 未结 1 1283
谎友^
谎友^ 2021-01-23 17:15

For the following code, I can read all the data in the string, and successfully get the data for plot.

NSMutableArray *contentArray = [NSMutableArray array];
         


        
相关标签:
1条回答
  • 2021-01-23 18:02

    I setup a sample project and tried this code and it worked.

    The two most probable points of error are

    1. you aren't getting the file path (i.e. filePath is nil)
    2. you aren't reading the file correctly.

    I would suggest adding:

    NSLog( @"filePath: %@", filePath );
    
    NSLog( @"Data: %@", Data );
    

    and changing:

    NSString *Data = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil ];    
    

    to

    NSError*  error;
    NSString* Data = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:&error ];    
    

    and then adding:

    NSLog( @"error: %@", error );
    

    Of course, running this through the debugger and checking the return values should work as well and let you know exactly where it is failing.

    0 讨论(0)
提交回复
热议问题