对于一些代码有一点问题,在运行相应的操作后返回上面列出的错误:
- (IBAction)uploadData:(id)sender {
NSMutableArray *uploadArray = [[NSMutableArray alloc]init];
[uploadArray addObject:@"hire.csv"];
[uploadArray addObject:@"equipment.csv"];
[uploadArray addObject:@"signature.png"];
NSString * docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0];
NSString * proof1 = [docPath stringByAppendingPathComponent:@"proof1.png"];
if([[NSFileManager defaultManager] fileExistsAtPath: proof1])
{
[uploadArray addObject:@"proof1.png"];
}
NSString * proof2 = [docPath stringByAppendingPathComponent:@"proof2.png"];
if([[NSFileManager defaultManager] fileExistsAtPath: proof2])
{
[uploadArray addObject:@"proof2.png"];
}
NSString * proof3 = [docPath stringByAppendingPathComponent:@"proof3.png"];
if([[NSFileManager defaultManager] fileExistsAtPath: proof3])
{
[uploadArray addObject:@"proof3.png"];
}
int arrayCount = [uploadArray count];
int i = 0;
NSString *arrayString;
for (i = 0; i < arrayCount; i++)
{
uploadArray[i] = arrayString;
if(arrayString != nil)
{
NSString * uploadString = [docPath stringByAppendingPathComponent:arrayString];
[self upload:uploadString ftpUrl:@"ftp.xxxxxxxx.com/xx/xx" ftpUsr:@"xxx" ftpPass:@"xxx"];
}
NSLog(uploadArray[i]);
}
}
现在,如果我禁用for循环中的所有内容,除了NSLog()
我没有错误,它会返回数组中正确的对象列表。
这对我来说,没有一个对象应该返回nil,当然?
有谁能帮我发现我做错了什么? (可能相当多,因为我对这个东西很新)
答案 0 :(得分:0)
由于您的错误清楚统计数据,您正在向数组添加一个nil对象,这是不允许的。
在下面的代码中,您没有为arrayString
分配任何内容使其成为零。然后尝试将其添加到阵列中。
NSString *arrayString;
for (i = 0; i < arrayCount; i++)
{
uploadArray[i] = arrayString;
从代码的外观来看,您试图将数组中的每个元素添加到字符串中。你这样做是错误的。您需要NSMutableString
并执行以下操作:
[arrayString appendString: uploadArray[i]];