When I'm clicking button I'm getting this exception.I don't know where I'm doing wrong Someone help me .my app is rejected because of this exception
my code:
UILabel *rememberMeLabelObj = [[UILabel alloc]initWithFrame:CGRectMake(xaxisForRememberMeLabel, yaxisForRememberMeLabel, widthForRememberMeLabel, heightForRememberMeLabel)];
rememberMeLabelObj.text = #"Remember me";
rememberMeLabelObj.font =[UIFont systemFontOfSize:14.0];
rememberMeLabelObj.textColor = [UIColor colorWithRed:0.816f green:0.592f blue:0.157f alpha:1.00f];
[self.view addSubview:rememberMeLabelObj];
You are calling UILabel frame methods, and probably calculating the value somehow and the result is a NaN, which means "not a number" and, as you correctly suggested, it can be the result of o divide-by-zero operation.
But it can appear for a lot other reasons: http://en.wikipedia.org/wiki/NaN
Reference: kuba
I solved my issue actually I didn't gave float values because of this I got exception.I gave CGFloat and gave values as integer like 400,350,etc but I need give 400.0f .so,I got this issue .Now it was cleared
My iOS App has the same problem when the simulator version is 8.x, it is no problem in version 9.x,after I have checked and removed the following code, the problem is solved!
- (void)viewWillAppear:(BOOL)animated
{
[LoadTableView setContentOffset:CGPointMake(CGFLOAT_MAX, CGFLOAT_MAX)];
[super viewWillAppear:YES];
}
- (void)viewDidAppear:(BOOL)animated
{
[LoadTableView reloadData];
LoadTableView.hidden = 0;
[super viewDidAppear:YES];
}
Related
I have an ordinary tableview with custom cells, working perfectly on iOS 6.0 but after upgrading the app to iOS 10, scattered problem arises.
Note: The app works as expected on iPhone 5, both on simulator and on a real device. All devices are running iOS 10.2 but iPhone 6 and above has the issues described below.
Some tableviews work fine just like before, while one of the tableViews always shows exactly 1 cell (even tough cellForRowAtIndexPath is called 7 times) and another table shows no cells at all despite cellForRowAtIndexPath getting called twice.
I am wondering why the method is called if the tableview does not care to display the result?
I am at a total loss as to what is going on and how to fix it. Been at it for a day with no progress at all. I have tried cleaning and running different builds and can not get the affected tableviews to behave correctly. I don't know what to try next? Any help is appreciated, thanks!
Ok since you need some code here is a part of it that is not that sensitive. DataSource:
- (void)viewDidLoad
{
[super viewDidLoad];
NOSUserInfo2 *userInfo = [S24SharedUserHandler currentUser];
dataSource = [NSMutableArray arrayWithArray:[userInfo children]];
if([userInfo student] || [userInfo teacher])
{
[dataSource insertObject:userInfo atIndex:0];
}
self.contentSizeForViewInPopover = CGSizeMake(250, 45*dataSource.count-1);
self.tableView.backgroundColor=[UIColor colorWithWhite:0.95f alpha:1];
self.tableView.scrollEnabled=NO;
[self.tableView registerNib:[UINib nibWithNibName:#"NOSPersonSelectorCell" bundle:nil] forCellReuseIdentifier:#"PersonPopoverCell"];
}
This gets called 2 times:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"PersonPopoverCell";
NOSPersonSelectorCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
cell.textLabel.font = [UIFont fontWithName:#"HelveticaNeue-Medium" size:15];
cell.textLabel.backgroundColor=[UIColor clearColor];
NSObject *dataObject = [dataSource objectAtIndex:[indexPath row]];
if ([dataObject isKindOfClass:[NOSUserInfo2 class]]) {
cell.textLabel.text = [(NOSUserInfo2 *)dataObject name];
cell.pk = [(NOSUserInfo2 *)dataObject personPK];
}
else {
cell.textLabel.text = [(NOSChild2 *)dataObject childName];
cell.pk = [(NOSChild2 *)dataObject childPK];
}
cell.textLabel.textColor = [UIColor colorWithWhite:0.18f alpha:1];
//NSLog(#"%d", [S24SharedUserHandler selectedPk]);
cell.checkmark.hidden=cell.pk!=[S24SharedUserHandler selectedPk];
return cell;
}
And the result is that the tableview is empty.
New information 11 Jan 2017
The app works when testing on phone, but not on simulator. I still have no idea what is wrong and am really dissapointed in the downvotes I am still getting for asking this question. I would appreciate if somebody can explain why they think it is a bad question.
Apparently everything works on an iPhone 5. It does not work on iPhone 6 and up. Be advised that the iOS is still 10.2, for both the iPhone 5 and iPhone 6 and 7 also have iOS 10.2
Since the only difference between working and not working is the device, not ios version, I am now leaning towards it being an UI bug that only occurs at certain sizes.
One other issue that arises is that my gesturerecognizer also only works on iPhone5 and not 6+
New info!
I can fix the problem by commenting the heightForRowAtIndexPath code. This now means that I need some other way to adjust the height of certain cells and that is the current problem. I still have no idea at all why uitableview behaves this way.
The reason for this particular problem was that the method "heightForRowAtIndexPath" returns a double on iPhone 5 and long on iPhone 6, to be correct, one should use a defined datatype called "CGFloat"!
It was not easy to find this problem and I hope I can help someone else with this. Also thanks to anyone that tried to help!
This problem can be demonstrated by creating a new project in Xcode (I am using version 6.4) and using the following code:
#interface ViewController ()
#property (nonatomic, strong) UITextField * myTextField;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.myTextField = [[UITextField alloc] initWithFrame:CGRectMake(50, 50, self.view.frame.size.width-100, 50)];
self.myTextField.textAlignment = NSTextAlignmentRight;
[self.myTextField becomeFirstResponder];
self.myTextField.backgroundColor = [UIColor lightGrayColor]
self.myTextField.adjustsFontSizeToFitWidth = YES;
self.myTextField.font = [UIFont systemFontOfSize:40];
[self.view addSubview:self.myTextField];
}
- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
self.myTextField.text = #"1.5241578750119E18";
}
When running this project in iOS Simulator (iPhone 5 or 5S), the cursor is initially displayed after the last "1", and the "8" is not visible until a new character is typed.
This appears to be a bug by Apple, but my question is: is there a workaround for now that will force the text to right-align and show the cursor in the correct position?
To clarify the question further, the issue occurs when the text is set programmatically. I expect to see this:
But instead I am seeing this (note that the entire number is not visible and the cursor is showing after the "1" instead of the last digit which is an "8"):
This is a bug, existing in iOS, since iOS 7. Issue can be reproduced in stock applications like Settings as well. It affects text fields only when NSTextAlignmentRight is used. The original bug ID logged into Radar for this issue is 14485694. You may use centre or left text alignments, to circumvent this problem.
I would also suggest to file a new bug report to Apple,
Try this
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 20)];
self.myTextField.leftView = paddingView;
self.myTextField.leftViewMode = UITextFieldViewModeAlways;
it will add some space to the left side of your TextField so that your cursor starts at correct position.
Hope it helps.
If I change your code to this:
- (void)viewDidLoad {
[super viewDidLoad];
self.myTextField = [[UITextField alloc] initWithFrame:CGRectMake(5, 50, self.view.frame.size.width-10, 50)];
self.myTextField.textAlignment = NSTextAlignmentRight;
[self.myTextField becomeFirstResponder];
self.myTextField.backgroundColor = [UIColor lightGrayColor];
self.myTextField.adjustsFontSizeToFitWidth = YES;
self.myTextField.font = [UIFont systemFontOfSize:60];
[self.view addSubview:self.myTextField];
}
And start typing in those numbers, the cursor ends up along the right edge of the text field just as it's supposed to.
Even when I start the app with the default value in the text, I see the cursor along the right edge of the text field fine.
Listening to UITextFieldTextDidChangeNotification notification instead of UIControlEventEditingChanged will fix the issue.
I met the same issue, try add dummy code like this
(void)textFieldDidBeginEditing:(UITextField *)textField {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
textField.text = textField.text;
});
}
I was using InAppSettings to manage my settings but it stopped working in iOS 7 and I couldn't figure out why. So I set out to build my own simple settings tableView. In cellForRowAtIndexPath: I make a slider and add it to my cell like this:
UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(really ugly frame code)];
slider.minimumValue = 0;
slider.maximumValue = 7;
slider.value = 4;
slider.userInteractionEnabled = YES;
[slider addTarget:self action:#selector(slide:) forControlEvents:UIControlEventValueChanged];
[cell addSubview:slider];
The slider shows up perfectly, but I can't interact with it! No matter what I do it won't move. And the target action never gets fired either. The exact same bug I was having with InAppSettings to begin with.
It feels like I am missing something simple, anybody see this before?
Weird. I guess I was initializing the UISlider incorrectly. This code works.
I'm currently trying to create an SMS-like screen, where the user can write some text and send it to other users. Everything goes as expected until I try to clear my text view and encounters a crash.
I've been trying to find a way around this issue, but I just cannot find enough documentation online. So here it is, and hopefully one of you will know a fix for this.
The implementation
My UITextView is a subclass of Peter Steinberger's implementation for iOS7, and I use it with a custom NSTextStorage subclassed as showed in objc.io's 'Getting to Know TextKit' and especially that source code in order to highlight usernames in the message.
In my ViewController, I configure my text storage like this:
self.textStorage = [[[MyCustomTextStorage alloc] init] autorelease];
[self.textStorage addLayoutManager:self.textView.layoutManager];
And then in my TextView's delegate method:
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
I store the input in my custom TextStorage:
[self.textStorage.string stringByReplacingCharactersInRange:range withString:text];
The crash
I can retrieve my text via self.textStorage.string, and then I clear my text view by replacing characters in the range of the input string. This works quite well, but when I try to set my TextView as the first responder again, the application crashes.
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSCFString _getBlockStart:end:contentsEnd:forRange:stopAtLineSeparators:]: Range {5, 0} out of bounds; string length 0'
The range mentioned is the range of my previously cleared string so it looks like I can clear the display, but my TextStorage / TextView is keeping a reference to the first edited range / string.
Any idea on what could be causing this crash and how to resolve it?
Thanks for your attention; at this point any help is appreciated, so please feel free to post if you have some piece of advice. :)
The reason it's crashing is because you are using a range that it outside the bounds of the string in the textStorage. If you want to clear the textView why not just use self.textStorage.string=#""
Same situation with you.
It costed me half a day to solve it.
The example you provide is right.
Your app will crash not only when you are clearing it, but also when using -setText: every time.
They don't crash beacause they would never call -setText:!!!
Solution:
add all TextKit staffs you need to your code,
like this:
_textStorage = [[NSTextStorage alloc] init];
_layoutManager = [[NSLayoutManager alloc] init];
[_textStorage addLayoutManager:_layoutManager];
_textContainer = [[NSTextContainer alloc] init];
[_layoutManager addTextContainer:_textContainer];
_myTextView = [[UITextView alloc] initWithFrame:frame textContainer:_textContainer];
Actually, you missed the NSTextContainer, so there's no right container for string to put in, then the app crashed.
Maybe you can send pull requests to these two demo project, for not miss leading other people.
After replacing text, try:
[self setSelectedRange:NSMakeRange(0, 0)];
I have an app that runs perfectly on iOS 6. I've set a blinking effect to a UISlider's thumb this way:
-(void)startBlinkingSlider{
isSliderBlinking = YES;
isSliderTinted = NO;
[self performSelector:#selector(toggleSliderColor) withObject:nil afterDelay:0.2];
}
-(void)toggleSliderColor{
if(isSliderBlinking){
if(isSliderTinted){
self.effectAmountSlider.thumbTintColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1];
}else{
self.effectAmountSlider.thumbTintColor = [UIColor colorWithRed:255 green:0 blue:0 alpha:1];
}
isSliderTinted = !isSliderTinted;
[self performSelector:#selector(toggleSliderColor) withObject:nil afterDelay:0.2];
}
}
-(void)stopBlinkingSlider{
isSliderBlinking = NO;
isSliderTinted = NO;
self.effectAmountSlider.thumbTintColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1];
}
When I call startBlinkingSlider my slider starts blinking red in iOS 6. If I run the same exact app on my iOS 7 device, nothing happens. The slider's thumb retains its original white color. I've set a breakpoint on the line where I set the thumbTintColor. In debugger, here is what I'm getting:
(lldb) po self.effectAmountSlider.thumbTintColor
error: failed to get API lock
(lldb) po self.effectAmountSlider.thumbTintColor
UIDeviceRGBColorSpace 0 0 0 1
(lldb)
I typed the exact same code and got a weird message in the first one. However, the second result is correct. Then after setting it to red I'm also getting the correct result:
(lldb) po self.effectAmountSlider.thumbTintColor
UIDeviceRGBColorSpace 1 0 0 1
Even though the debugger shows the correct value, I'm getting no visual change in the slider. It's still white, color doesn't change in any way. I've searched Apple's documents here: https://developer.apple.com/library/ios/documentation/userexperience/conceptual/TransitionGuide/Controls.html
It doesn't say anything about UISlider's thumbTintColor not working as iOS 6. It should stay working as expected. I've checked the thread and everything is running on the main thread. toggleSliderColor is always on the main thread so it's not a threading issue. Why is my thumb color not working?
Thanks, Can.
I discovered a workaround. By first calling the 'setThumbImage:forState:' method, the 'thumbTintColor' property will then take effect.
[self.slider setThumbImage:[UIImage imageNamed:#"Thumb.png"]
forState:UIControlStateNormal];
self.slider.thumbTintColor = [UIColor blackColor];
I tested this on Version 7.0 (463.9.4.2) of iOS Simulator.
I just so happened to read the iOS 7 UI Transition Guide again this morning, and tripped on a statement under Slider. If EITHER maximumTrackTineColor OR thumbTintColor are nil, then both properties are ignored. So I tried to set all the tint colors, thumb still white.
I entered a bug report on this - #15277127 - reference it if you enter your own bug. The more bug reports the more likely Apple will fix it soon.
EDIT: Apple duped my bug to another one - this was obviously known a while ago.
On basis of #aaronsti's answer I found that the following worked for me. Setting thumb-image to nil had no effect.
[_slider setThumbImage:[_slider thumbImageForState:UIControlStateNormal] forState:UIControlStateNormal];
_slider.minimumTrackTintColor = minTintColor;
_slider.thumbTintColor = thumbTintColor;
So far in Xcode 6.2, iOS 8.2 the problem is still there, and the workaround still works. Swift version:
slider.setThumbImage(slider.thumbImageForState(.Normal), forState:.Normal)