当我设置UIButton
的背景图像时,我收到此错误PlayeridViewController.h
@interface PlayeridViewController ()
@property (strong, nonatomic) IBOutlet UIButton *gotoboard;
@property (strong, nonatomic) IBOutlet UILabel *newplayerlbl;
@property (strong, nonatomic) IBOutlet UILabel *tetpid;
@end
以下是我的观点加载方法
- (void)viewDidLoad {
[super viewDidLoad];
UIImageView *bgView = [[UIImageView alloc] initWithFrame:self.view.bounds];
bgView.image = [UIImage imageNamed:@"Loginbg"];
[self.view insertSubview:bgView atIndex:0];
_newplayerlbl.hidden=NO;
_tetpid.hidden=NO;
//Code that presents or dismisses a view controller here
_newplayerlbl.text=[NSString stringWithFormat:@"%@",_playerid];
NSLog(@"%@",_playerid);
[_gotoboard setBackgroundImage:[UIImage imageNamed:@"go to board"] forState:UIControlStateNormal];
[_gotoboard setBackgroundImage:[UIImage imageNamed:@"go to board"] forState:UIControlStateHighlighted];
// Do any additional setup after loading the view.
}
- (IBAction)gotoboard:(id)sender {
//Code that presents or dismisses a view controller here
[self performSegueWithIdentifier:@"b4" sender:self];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
它在最后一行崩溃了,我尝试了dispatch_async
下我使用的行
_newplayerlbl.hidden=NO;
到
[_gotoboard setBackgroundImage:[UIImage imageNamed:@"go to board"] forState:UIControlStateHighlighted];
这次崩溃了
这是什么问题?解决办法是什么? 在此先感谢
我的异常消息是
2017-08-17 10:31:04.528 BarrelBoard[13094:83433] *** Assertion failure in -[UIKeyboardTaskQueue waitUntilAllTasksAreFinished], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3600.7.47/Keyboard/UIKeyboardTaskQueue.m:432
2017-08-17 10:31:04.538 BarrelBoard[13094:83433] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '- [UIKeyboardTaskQueue waitUntilAllTasksAreFinished] may only be called from the main thread.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010364bb0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00000001030b0141 objc_exception_throw + 48
2 CoreFoundation 0x000000010364fcf2 +[NSException raise:format:arguments:] + 98
3 Foundation 0x0000000102c4a536 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
4 UIKit 0x0000000104c95f6f -[UIKeyboardTaskQueue waitUntilAllTasksAreFinished] + 165
5 UIKit 0x0000000104416515 -[UIKeyboardImpl setDelegate:force:] + 1372
6 UIKit 0x000000010482c63d -[UIPeripheralHost(UIKitInternal) _reloadInputViewsForResponder:] + 992
7 UIKit 0x0000000104835c4b -[UIPeripheralHost(UIKitInternal) _preserveInputViewsWithId:animated:reset:] + 499
8 UIKit 0x000000010430c35d -[UIViewController _presentViewController:modalSourceViewController:presentationController:animationController:interactionController:completion:] + 1145
9 UIKit 0x000000010430dfae -[UIViewController _presentViewController:withAnimationController:completion:] + 4660
10 UIKit 0x0000000104310e8a -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 532
11 UIKit 0x0000000104310962 -[UIViewController presentViewController:animated:completion:] + 181
12 UIKit 0x0000000104315c94 -[UIViewController _showViewController:withAction:sender:] + 274
13 UIKit 0x00000001047c6fe1 __66-[UIStoryboardShowSegueTemplate newDefaultPerformHandlerForSegue:]_block_invoke + 134
14 UIKit 0x0000000104920444 -[UIStoryboardSegueTemplate _performWithDestinationViewController:sender:] + 447
15 UIKit 0x0000000104920254 -[UIStoryboardSegueTemplate _perform:] + 82
16 UIKit 0x00000001042fde47 -[UIViewController performSegueWithIdentifier:sender:] + 99
17 BarrelBoard 0x0000000102acedb9 __32-[MemberViewController submitb:]_block_invoke + 441
18 CFNetwork 0x000000010601b87b __75-[__NSURLSessionLocal taskForClass:request:uploadFile:bodyData:completion:]_block_invoke + 19
19 CFNetwork 0x000000010601b095 __49-[__NSCFLocalSessionTask _task_onqueue_didFinish]_block_invoke + 143
20 Foundation 0x0000000102bba3b7 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 7
21 Foundation 0x0000000102bba0bb -[NSBlockOperation main] + 101
22 Foundation 0x0000000102bb8877 -[__NSOperationInternal _start:] + 627
23 Foundation 0x0000000102bb45fc __NSOQSchedule_f + 198
24 libdispatch.dylib 0x0000000106b5205c _dispatch_client_callout + 8
25 libdispatch.dylib 0x0000000106b3094f _dispatch_queue_serial_drain + 221
26 libdispatch.dylib 0x0000000106b31669 _dispatch_queue_invoke + 1084
27 libdispatch.dylib 0x0000000106b33ec4 _dispatch_root_queue_drain + 634
28 libdispatch.dylib 0x0000000106b33bef _dispatch_worker_thread3 + 123
29 libsystem_pthread.dylib 0x0000000106ee95a2 _pthread_wqthread + 1299
30 libsystem_pthread.dylib 0x0000000106ee907d start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
以下是我的提交代码
- (IBAction)submitb:(id)sender {
dispatch_async(dispatch_get_main_queue(), ^{
if (_phonum.text.length==10) {
_memnums=[NSString stringWithFormat:@"%@",_memnum.text];
_phonums=[NSString stringWithFormat:@"%@",_phonum.text];
NSLog(@"%@ %@",_memnums,_phonums);
NSString *post = [NSString stringWithFormat:@"membership_number=%@ & phone_number= %@",_memnums,_phonums];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
// Next up, we read the postData's length, so we can pass it along in the request.
NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]];
// Now that we have what we'd like to post, we can create an NSMutableURLRequest, and include our postData
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"http://riterp.com/barrel/getplayer_id.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:postData];
NSLog(@"the data Details is %@", post);
// And finally, we can send our request, and read the reply by creating a new NSURLSession:
NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
[[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSString *requestReply = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; // this is json string
NSLog(@"Reply = %@", requestReply);
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; // you need to convert to dictionary object
NSLog(@"requestReply: %@", jsonDict);
_playerd=[jsonDict valueForKey:@"player_id"];
[self performSegueWithIdentifier:@"b2" sender:self];
}] resume];
}
else{
_errorimg.hidden=NO;
_phonenumanim.duration=0.5;
_phonenumanim.type=CSAnimationTypeShake;
_phonenumanim.delay=0.5;
[self.view addSubview:_phonenumanim];
[_phonenumanim startCanvasAnimation];
UIAlertController *alertController=[UIAlertController alertControllerWithTitle:@"Incorrect Phone Number!!" message:@"Please enter a valid Phone Number!" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action)
{
}];
[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];
}
});
}
答案 0 :(得分:0)
崩溃日志中的问题指向从后台线程中MemberViewController
的提交方法执行segue。
答案 1 :(得分:0)
您应该从主线程执行您的segue,如错误消息所示。将代码包含在[MemberViewController submitb:]
中的任务完成块中的GCD调用中,例如: G:
// Inside of the completion block
dispatch_async(dispatch_get_main_queue(), ^{
// Insert the code of the completion block here
[self performSegue...];
});
答案 2 :(得分:0)
实际上我尝试从post方法中取出segue代码,现在它可以正常工作而不会出错提交按钮操作。 [self performSegueWithIdentifier:@“b2”sender:self];被取消了post方法