Comments (12)
That's really weird, because the constraints are the same (as in, they represent the same items and values). At the same time, the constraints shouldn't be created twice, so I would consider this a problem.
Can you show me the full initialization of the alert?
from sdcalertview.
@jasperblues do you have an update on this?
from sdcalertview.
Sorry for the delay!
Everywhere in the app uses one of the following:
- (void)presentMessage:(NSString *)message
{
dispatch_async(dispatch_get_main_queue(), ^{
SDCAlertController
*alert = [SDCAlertController alertControllerWithTitle:@"" message:message preferredStyle:SDCAlertControllerStyleAlert];
[alert setVisualStyle:[INFAlertStyle style]];
[alert addAction:[SDCAlertAction actionWithTitle:@"OK" style:SDCAlertActionStyleDefault handler:nil]];
[alert presentWithCompletion:nil];
});
}
or
- (void)presentError:(NSError *)error
{
dispatch_async(dispatch_get_main_queue(), ^{
[ICLoader dismiss];
[self presentMessage:[error inf_displayMessage]];
LogError(@"*** Error: *** \n%@\n%@", [error inf_displayMessage], error);
});
}
Except for two places where we're presenting a frosty overlay over a camera feed. In those cases it seems SDCAlertController wasn't happy so SDCAlertView was used instead:
- (void)willSignUp:(INFSignUpRequest *)request
{
[redacted]
else {
SDCAlertView *alert = [[SDCAlertView alloc] init];
[alert addButtonWithTitle:@"DECLINE"];
[alert addButtonWithTitle:@"ACCEPT"];
NSString
*privacyText = [redacted]
PrivacyAlertContentView *contentView = [PrivacyAlertContentView viewWithText:privacyText];
contentView.onViewPrivacyPolicyTapped = ^{
[alert dismissWithClickedButtonIndex:0 animated:YES];
[self willViewPrivacyPolicy];
};
[alert.contentView addSubview:contentView];
[alert showWithDismissHandler:^(NSInteger buttonIndex) {
if (buttonIndex == 1) {
_isPrivacyPolicyAccepted = YES;
[self doSignUp:request];
}
}];
}
}
or
- (void)processSignedUser:(User *)user fromRequest:(SignUpRequest *)request
{
[redacted]
else {
SDCAlertView *alert = [[SDCAlertView alloc] init];
[alert addButtonWithTitle:@"PROCEED"];
[alert addButtonWithTitle:@"TRY AGAIN"];
NSString *message = @"We can't validate your ownership . . . [redacted]";
alert.attributedMessage = [[NSAttributedString alloc] initWithString:message attributes:@{
NSFontAttributeName : [UIFont applicationFontOfSize:15]
}];
[alert showWithDismissHandler:^(NSInteger buttonIndex) {
if (buttonIndex == 1) {
[redacted]
}];
}
else {
[self backToHomeController];
}
}];
}
}
from sdcalertview.
I'm not sure what's going on here. I wonder if this still happens if you don't use a custom visual style and/or a non-empty title. I've been trying to replicate this, but haven't been able to.
from sdcalertview.
I’ll test that out and get back to you shortly. If that doesn’t yield any information, I’ll see if I can strip down a sample project for you.
from sdcalertview.
@sberrevoets I am seeing a similar issue, if I try to show the following alert,
SDCAlertController *alert = [SDCAlertController alertControllerWithTitle:@"Test Title" message:@"Test Message, that is longer than one line. 1 2 3 4 5 6 7" preferredStyle:SDCAlertControllerStyleAlert];
[alert addTextFieldWithConfigurationHandler:nil];
[alert addAction:[SDCAlertAction actionWithTitle:@"Okay" style:SDCAlertActionStyleDefault handler:nil]];
[alert addAction:[SDCAlertAction actionWithTitle:@"Cancel" style:SDCAlertActionStyleCancel handler:nil]];
[self presentViewController:alert animated:TRUE completion:nil];
in iOS 8.1, I get the following ... which is really only a warning, not an error ... BUT I only get the warning when the message line is long enough to wrap around. In iOS 7.1 I don't get the warning but the app will a stack trace (see farther below for that message). Note, that I get this crash regardless of whether the line wraps (or if I have a text field or buttons).
2014-11-14 23:03:42.404 Team Shake [19442:975417] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x7ff341d39fe0 SDCAlertLabel:0x7ff341f25610'Test Message, that is lon...'.firstBaseline == SDCAlertLabel:0x7ff341f4ee60'Test Title'.lastBaseline + 18>",
"<NSLayoutConstraint:0x7ff341e51e20 SDCAlertLabel:0x7ff341f25610'Test Message, that is lon...'.firstBaseline == SDCAlertLabel:0x7ff341f4ee60'Test Title'.lastBaseline + 18>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7ff341d39fe0 SDCAlertLabel:0x7ff341f25610'Test Message, that is lon...'.firstBaseline == SDCAlertLabel:0x7ff341f4ee60'Test Title'.lastBaseline + 18>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2014-11-14 23:03:42.405 Team Shake[19442:975417] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x7ff341e51e20 SDCAlertLabel:0x7ff341f25610'Test Message, that is lon...'.firstBaseline == SDCAlertLabel:0x7ff341f4ee60'Test Title'.lastBaseline + 18>",
"<NSLayoutConstraint:0x7ff341f38e70 SDCAlertLabel:0x7ff341f25610'Test Message, that is lon...'.firstBaseline == SDCAlertLabel:0x7ff341f4ee60'Test Title'.lastBaseline + 18>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7ff341e51e20 SDCAlertLabel:0x7ff341f25610'Test Message, that is lon...'.firstBaseline == SDCAlertLabel:0x7ff341f4ee60'Test Title'.lastBaseline + 18>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2014-11-14 23:03:42.406 Team Shake[19442:975417] -[SDCAlertControllerScrollView setConstraints]:112
------- 3 - <SDCAlertControllerScrollView: 0x7ff341f359a0; baseClass = UIScrollView; frame = (0 0; 270 114); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x7ff341f3ca60>; layer = <CALayer: 0x7ff341f35d30>; contentOffset: {0, 0}; contentSize: {0, 114}>
However, in the iOS 7.1 simulator, the app will crash with the following error
2014-11-14 23:01:40.355 Team Shake[19394:613] *** Assertion failure in -[SDCAlertControllerScrollView layoutSublayersOfLayer:], /SourceCache/UIKit_Sim/UIKit-2935.137/UIView.m:8794
2014-11-14 23:01:40.359 Team Shake[19394:613] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after executing -layoutSubviews. SDCAlertControllerScrollView's implementation of -layoutSubviews needs to call super.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010a8a5495 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010cf5d99e objc_exception_throw + 43
2 CoreFoundation 0x000000010a8a531a +[NSException raise:format:arguments:] + 106
3 Foundation 0x000000010b05bf19 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 189
4 UIKit 0x000000010b534a3a -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 521
5 QuartzCore 0x000000010ac1b802 -[CALayer layoutSublayers] + 151
6 QuartzCore 0x000000010ac10369 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 363
7 UIKit 0x000000010b528f70 -[UIView(Hierarchy) layoutBelowIfNeeded] + 521
8 Team Shake 0x000000010a20bf0d -[SDCAlertControllerView prepareForDisplay] + 509
9 Team Shake 0x000000010a18f49d -[SDCAlertController viewWillAppear:] + 829
10 UIKit 0x000000010b5cddb5 -[UIViewController _setViewAppearState:isAnimating:] + 422
11 UIKit 0x000000010b827410 -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:animation:] + 5629
12 UIKit 0x000000010b5d4fce -[UIViewController presentViewController:withTransition:completion:] + 4854
13 Team Shake 0x000000010a17f17a -[MainViewController addUser] + 410
14 UIKit 0x000000010b4d5f06 -[UIApplication sendAction:to:from:forEvent:] + 80
15 UIKit 0x000000010b4d5f06 -[UIApplication sendAction:to:from:forEvent:] + 80
16 UIKit 0x000000010b4d5eb4 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 17
17 UIKit 0x000000010b5b2880 -[UIControl _sendActionsForEvents:withEvent:] + 203
18 UIKit 0x000000010b5b1dc0 -[UIControl touchesEnded:withEvent:] + 530
19 UIKit 0x000000010b50cd05 -[UIWindow _sendTouchesForEvent:] + 701
20 UIKit 0x000000010b50d6e4 -[UIWindow sendEvent:] + 925
21 UIKit 0x000000010b4e529a -[UIApplication sendEvent:] + 211
22 UIKit 0x000000010b4d2aed _UIApplicationHandleEventQueue + 9579
23 CoreFoundation 0x000000010a834d21 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
24 CoreFoundation 0x000000010a8345f2 __CFRunLoopDoSources0 + 242
25 CoreFoundation 0x000000010a85046f __CFRunLoopRun + 767
26 CoreFoundation 0x000000010a84fd83 CFRunLoopRunSpecific + 467
27 GraphicsServices 0x000000010e0a4f04 GSEventRunModal + 161
28 UIKit 0x000000010b4d4e33 UIApplicationMain + 1010
29 Team Shake 0x000000010a15c754 main + 68
30 libdyld.dylib 0x000000010d99a5c9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
from sdcalertview.
Thanks for the detailed report @redshoulderedhawk, that helps tremendously! I'll take a look soon, because you can't be the only one running into these problems.
from sdcalertview.
I was finally able to resolve this. I knew it wasn't a good idea to create constraints in layoutSubviews
. I've tried in both iOS 7 and iOS 8, and I'm not getting warnings or crashes now.
@redshoulderedhawk Please note that in your example, the crash on iOS 7 happens because you use -[UIViewController presentViewController:animated:completion:]
. This doesn't work on iOS 7 because a view controller won't be presented. If you want to preserve iOS 7 compatibility, please use -[SDCAlertController presentWithCompletion:]
. Internally, it will make the decision to show the view controller or a separate window (as was the case in iOS 7).
from sdcalertview.
@sberrevoets thanks for the update and pointing out the problem with using presentViewController in iOS7! However, I'm still running into the same problem with SDCAlertViewController which made me look into these warning messages to begin with. Specifically I am trying to present an SDCAlertviewController with TextField in response to a button press in a UIActionSheet, but it does not work as expected. If I use "[alert presentWithCompletion:nil];”, the alert pops up and immediately disappears. If I use "[self presentViewController:alert animated:true completion:nil];” the alert pops up and stays up (in iOS8 … as you pointed out this does not work at all in iOS7). However, I get some very weird effects with the action sheet disappearing, the keyboard popping up, and then the action sheet reappearing over the keyboard only to disappear again. I’m hoping there is some good way to use an SDCAlertController with a UIActionSheet, but its not obvious to me how it should be done. I would appreciate some pointers.
I have created a simple example below, which opens an UIActionSheet when a button is pressed. This might help to explain when this “situation” occurs:
#import "FirstViewController.h"
#import "SDCAlertController.h"
@interface FirstViewController ()
@end
@implementation FirstViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (IBAction) testAction:(id)sender {
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Test SDC",@"Test SDC", @"Test SDC",@"Test SDC",@"Test SDC",nil];
[sheet showInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
SDCAlertController *alert = [SDCAlertController alertControllerWithTitle:@"Test Alert"
message:@"test"
preferredStyle:SDCAlertControllerStyleAlert
];
[alert addTextFieldWithConfigurationHandler:nil];
[alert addAction:[SDCAlertAction actionWithTitle:@"Okay" style:SDCAlertActionStyleDefault handler:nil]];
[alert addAction:[SDCAlertAction actionWithTitle:@"Cancel" style:SDCAlertActionStyleCancel handler:nil]];
// [alert presentWithCompletion:nil];
[self presentViewController:alert animated:true completion:nil];
}
@end
from sdcalertview.
I’m hoping there is some good way to use an SDCAlertController with a UIActionSheet
Unfortunately, there isn't really. In iOS 7, alerts and action sheets were shown in separate windows, and the moment you presented an SDCAlertView right after a UIAlertView or UIActionSheet, bad things would happen.
In iOS 8, all three are now presented in their own view controllers, which makes it a little easier, but the original problem still persists. In your specific case, if you use presentWithCompletion:
, the action sheet is the current view controller that will be presented from, but that's about to go away, and I guess that makes the alert go away too.
I'm not sure what could explain the behavior in the case of presentViewController:animated:completion:
, but it doesn't completely surprise me.
Your best chance of making this work is to use actionSheet:didDismissWithButtonIndex:
to present a new alert. If even that doesn't work, I'm afraid there's not much that can be done (other than rewriting SDCAlertController
to support action sheets as well).
from sdcalertview.
@sberrevoets, thanks! actionSheet:didDismissWithButtonIndex:
seemed to do the trick. I was even able to use it with iOS 7.1 with the presentWithCompletion
method. I think since this method gets called after the action sheet view is dismissed, it is able to properly add the alert to the view.
from sdcalertview.
Yes, presentWithCompletion:
should always work in both iOS 7 and 8, except if a UIActionSheet
or UIAlertView
is already up. It's presentViewController:animated:completion:
that most likely doesn't work on iOS 7.
from sdcalertview.
Related Issues (20)
- Swift 4.2 and Xcode 10.1 Compilation Issue HOT 2
- Swift 4.2 and Xcode 10.1 Compilation Issue HOT 2
- Convert to Swift 5 HOT 1
- SPM support HOT 7
- [Question] Exclude view from being dimmed HOT 1
- Error with Catalyst HOT 2
- AttributedTitle of AlertAction does not apply (Color, font, etc...) with ActionSheet
- Example app crash on iPad presenting UIAlertController
- Readme.md images cannot be loaded
- Evaluate support to popover ActionSheet on iPad HOT 3
- ActionSheet custom view vertical alignment
- Open components to inheritance outside SDCAlertView module HOT 4
- Rounded corners are circles instead of squircles
- Different look for dark theme in ios 13 and ios 12 HOT 6
- AlertController with preferredStyle of .actionSheet Does Not Correctly Display attributedTitle or attributedMessage
- Crash on iOS 15 HOT 2
- How to perform height animation on contentView correctly? HOT 1
- Warning when showing AlertView with textfield
- override var supportedInterfaceOrientations: UIInterfaceOrientationMask HOT 1
- Crash on tintColorDidChange HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sdcalertview.