我想通过点击段按钮停止运行while循环的过程但是我无法停止或中断循环,并且通过单击下一个按钮我想在循环时重新启动。
-(IBAction)SegmentClick:(id)sender
{
if (segmentcntrl.selectedSegment == 0)
{
min=100.0;
max=500.0;
}
else if (segmentcntrl.selectedSegment == 1)
{
min=500.0;
max=1024.0;
here i want to restart while-loop <-------
}
else if (segmentcntrl.selectedSegment == 2)
{
min=1024.0;
max=5120.0;
here i want to restart while-loop <-------
}
else if (segmentcntrl.selectedSegment == 3)
{
min=5120.0;
max=100000.0;
here i want to restart while-loop <-------
}
else if (segmentcntrl.selectedSegment == 4)
{
min=100.0;
max=100000.0;
here i want to restart while-loop <-------
}
[self calculateLargerfiles];
NSLog(@"called");
}
******这是我的循环******
while (file = [de nextObject])
{
//NSLog(@"file %@",file);
strPath = [NSString stringWithFormat:@"/Users/%@/",NSUserName()];
strPath = [strPath stringByAppendingString:file];
NSLog(@"path %@",strPath);
//[test addObject:file.lastPathComponent];
NSError *attributesError = nil;
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:strPath error:&attributesError];
NSNumber *fileSizeNumber = [fileAttributes objectForKey:NSFileSize];
long long fileSize = [fileSizeNumber longLongValue];
//NSLog(@"%lld",fileSize);
//float sizeKB = ((float)fileSize / 1000);
//NSLog(@"%f",sizeKB);
float sizeMB = ((float)fileSize / 1000000);
NSLog(@"%f",sizeMB);
if(sizeMB >=min && sizeMB<=max)
{
[arrPathList addObject:strPath];
[arrFiles addObject:file.lastPathComponent];
if (sizeMB >=1000.0)
{
float sizeGB = ((float)fileSize / 1000000000);
//NSLog(@"%f",sizeGB);
NSString *strSize = [NSString stringWithFormat:@"%.1f GB",sizeGB];
[arrSizes addObject:strSize];
}
else
{
NSString *strSize = [NSString stringWithFormat:@"%.1f MB",sizeMB];
[arrSizes addObject:strSize];
}
NSLog(@"%@",arrPathList);
NSLog(@"%@",arrFiles);
NSLog(@"%@",arrSizes);
dispatch_async(dispatch_get_main_queue(),^{
[tblLargefiles reloadData];
});
//[tblLargefiles reloadData];
}
}
NSLog(@"Path list %@",arrPathList);
NSLog(@"Files list %@",arrFiles);
NSLog(@"Sizes list %@",arrSizes);
//[tblLargefiles reloadData];
[progressBar setHidden:YES];
}
我可以停止循环吗?