我构建的应用程序有4 tab
(Tabbar Controller
),每个选项卡我updateArray
在 2 秒后调用一个函数()。我想在单击其他选项卡时,updateArray()
功能是杀死。我的问题是什么时候打开tab
,updateArray()
之后调用2s
,当我点击其他选项卡时,这个功能仍然被调用。
这是 updateArray()
-(void)updateArray{
while (loop)
{
[NSThread sleepForTimeInterval:2.0];
[FileCompletedArray removeAllObjects];
[temp removeAllObjects];
[UserNameArray removeAllObjects];
NSURL *url1 = [NSURL URLWithString:@"server"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL: url1] ;
NSMutableURLRequest *afRequest = [httpClient requestWithMethod:@"POST" path:nil parameters:params1] ;
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:afRequest];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Success");
NSString * parsexmlinput = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
NSLog(@"Response in Loop CompleteView: %@", parsexmlinput); //000400010001
// dispatch_async(dispatch_get_main_queue(), ^{
[self parseXMLFile:parsexmlinput];
NSLog(@"File Completed array: %@", FileCompletedArray);
NSLog(@"File Temp out array: %@", temp);
NSLog(@"File Completed count: %lu",(unsigned long)[ FileCompletedArray count]);
NSLog(@"File Temp out count: %lu", (unsigned long)[temp count]);
if([FileCompletedArray count] != [temp count])
{
temp = [FileCompletedArray mutableCopy];
NSLog(@"File Temp 1 array: %@", temp);
[_tableView reloadData];
NSLog(@"File Temp 2 array: %@", temp);
}
[alert dismissWithClickedButtonIndex:0 animated:YES];
//});
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"error: %@", error);
}
];
[httpClient enqueueHTTPRequestOperation:operation];
}
}
而在 viewwillappear()
-(void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
loop = YES;
temp = [FileCompletedArray mutableCopy];
[self performSelectorInBackground:@selector(updateArray) withObject:nil ];
}
在我的功能中,我使用[NSThread sleepForTimeInterval:2.0];
了 ,我不知道如何杀死它。你有什么建议吗?提前致谢