I have a UIView that is a subview of UIScrollView.
I've done this to set the content size in viewDidLoad (useful snippet I found on this site):
CGFloat scrollViewHeight = 0.0f;
for (UIView* view in self.scrollView.subviews)
{
scrollViewHeight += view.frame.size.height;
}
[self.scrollView setContentSize:(CGSizeMake(320, scrollViewHeight))];
Using NSLogs I've determined the content size height is greater than the height of the scroll view. But, it still won't scroll. (I'm only interested in vertical scrolling.)
Scrolling is enabled in IB, so what am I missing?
This also happened to me - seems like when view is loaded from nib file some resizing happens after viewDidLoad and even after viewWillAppear.
The call stack shows it is resizeWithOldSuperviewSize who is doing that
#0 0x0000f040 in -[ScrollView setContentSize:] at .../ScrollView.m:49
#1 0x00092863 in -[UIScrollView _resizeWithOldSuperviewSize:] ()
#2 0x0007357a in -[UIView(Geometry) resizeWithOldSuperviewSize:] ()
#3 0x00072178 in __46-[UIView(Geometry) resizeSubviewsWithOldSize:]_block_invoke_0 ()
#4 0x01ccb5a7 in __NSArrayChunkIterate ()
#5 0x01ca303f in __NSArrayEnumerate ()
#6 0x01ca2a16 in -[NSArray enumerateObjectsWithOptions:usingBlock:] ()
#7 0x0007210f in -[UIView(Geometry) resizeSubviewsWithOldSize:] ()
#8 0x0056d14c in -[UIView(AdditionalLayoutSupport) _is_layout] ()
#9 0x00076dfe in -[UIView(Hierarchy) layoutSubviews] ()
#10 0x0007e92d in -[UIView(CALayerDelegate) layoutSublayersOfLayer:] ()
#11 0x010fa6b0 in -[NSObject performSelector:withObject:] ()
#12 0x022a5fc0 in -[CALayer layoutSublayers] ()
#13 0x0229a33c in CA::Layer::layout_if_needed(CA::Transaction*) ()
#14 0x022a5eaf in -[CALayer layoutIfNeeded] ()
#15 0x0011d8cd in -[UIViewController window:setupWithInterfaceOrientation:] ()
#16 0x000661a6 in -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] ()
#17 0x00064cbf in -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] ()
#18 0x00064bd9 in -[UIWindow _setRotatableViewOrientation:duration:force:] ()
#19 0x00063e34 in __57-[UIWindow _updateToInterfaceOrientation:duration:force:]_block_invoke_0 ()
#20 0x00063c6e in -[UIWindow _updateToInterfaceOrientation:duration:force:] ()
#21 0x00064a29 in -[UIWindow setAutorotates:forceUpdateInterfaceOrientation:] ()
#22 0x00067922 in -[UIWindow setDelegate:] ()
#23 0x00111fec in -[UIViewController _tryBecomeRootViewControllerInWindow:] ()
#24 0x0005ebc4 in -[UIWindow addRootViewControllerViewIfPossible] ()
#25 0x0005edbf in -[UIWindow _setHidden:forced:] ()
#26 0x0005ef55 in -[UIWindow _orderFrontWithoutMakingKey] ()
#27 0x00067f67 in -[UIWindow makeKeyAndVisible] ()
#28 0x0000379a in -[AppDelegate application:didFinishLaunchingWithOptions:] at .../AppDelegate.m:24
I didn't find a proper solution yet except setting contentSize later by calling performSelector:withObject:afterDelay
-(void)viewDidLoad
{
[self performSelector:#selector(adjustScrollViewContentSize) withObject:nil afterDelay:0.1];
}
-(void)adjustScrollViewContentSize
{
_scrollView.contentSize = CGSizeMake(4000, 4000);
}
is userInteractionEnabled property equal to TRUE? Perhaps you have a subview over your scrollview that is stealing the touches?
I agree with Sepehr. Something else must be stealing your touches. You can test this buy adding UIScollViewDelegate to your class and add one of the event call back methods below. If when you touch your scroll view they dont get called then you know Sepehr is correct.
(void)scrollViewDidScroll:(UIScrollView *)scrollView
(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
The issue comes from auto layout setting the contentSize based on constraints. Since my view was complex and auto layout was not up to the task I solved it by overriding setContentView: and ignoring auto layouts zero height setContentSize: message.
#interface MyView : UIScrollView {}
#end
#implementation MyView
- (void)setContentSize:(CGSize)aSize {
if (aSize.height > 0)
[super setContentSize:aSize];
}
#end
As an alternative to the use of performSelector:withObject:afterDelay suggested by ddenis, you could call setContentSize in viewDidLayoutSubviews:
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
//do stuff here to calculate the content width and height
// ...
//then set the content size accordingly
[self.scrollView setContentSize:(CGSizeMake(contentWidth, contentHeight))];
}
Related
I have a table view and and tapping on any cell there is a detail view, my app get crashed when returning from detail to table list view, after going in detail view more than once.
#0 0x32d98f1c in objc_msgSend ()
#1 0x358da150 in _UIView ()
#2 0x358da040 in -[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:] ()
#3 0x358da080 in -[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:] ()
#4 0x358da080 in -[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:] ()
#5 0x358d9f38 in -[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:] ()
#6 0x358f81dc in -[UIView(Hierarchy) removeFromSuperview] ()
#7 0x359af870 in -[UIScrollView removeFromSuperview] ()
#8 0x35900180 in -[UIView dealloc] ()
#9 0x374ffd7a in -[NSObject(NSObject) release] ()
#10 0x358f8230 in -[UIView(Hierarchy) removeFromSuperview] ()
#11 0x35900180 in -[UIView dealloc] ()
#12 0x359afffc in -[UIScrollView dealloc] ()
#13 0x374ffd7a in -[NSObject(NSObject) release] ()
#14 0x3516f7f4 in __delayedPerformCleanup ()
#15 0x3754d526 in CFRunLoopTimerInvalidate ()
#16 0x375522ac in __CFRunLoopDoTimer ()
#17 0x37521a90 in __CFRunLoopRun ()
#18 0x3752150a in CFRunLoopRunSpecific ()
#19 0x37521418 in CFRunLoopRunInMode ()
#20 0x33e76d24 in GSEventRunModal ()
#21 0x3591d57c in -[UIApplication _run] ()
#22 0x3591a558 in UIApplicationMain ()
How can i track the main reason behind this crash.
Thanks for any help.
I think in detailView dealloc method you are releasing an object which
is already release. it may be one of the reason to crash the app
Could it possible, that you reuse the DetailViewController Variable and only change the Data ?
Because i think that's a retain/release problem.
I suggest you rerun with zombies enabled. That should help you to pin point the problem which is most likely to be a pointer to a released object.
I seem to be getting a crash right after doing [[CCDirector sharedDirector] popScene]. I am not really sure why. Any clues would help, thanks!
Crashlog:
#0 0x99e5ef84 in objc_msgSend ()
#1 0x302d543a in __NSFastEnumerationMutationHandler ()
#2 0x00046b46 in -[CCScheduler tick:] (self=0x1919ac0, _cmd=0x7b682, dt=0.0333320014) at /Users/Sup3rpanda/Dev/My Projects/Puzzle/libs/cocos2d/CCScheduler.m:211
#3 0x0001fb52 in -[CCDirector mainLoop] (self=0xf10a30, _cmd=0x76272) at /Users/Sup3rpanda/Dev/My Projects/Puzzle/libs/cocos2d/CCDirector.m:208
#4 0x305355cd in __NSFireTimer ()
#5 0x302454a0 in CFRunLoopRunSpecific ()
#6 0x30244628 in CFRunLoopRunInMode ()
#7 0x32044c31 in GSEventRunModal ()
#8 0x32044cf6 in GSEventRun ()
#9 0x309021ee in UIApplicationMain ()
#10 0x00002e94 in main (argc=1, argv=0xbfffef60) at /Users/Sup3rpanda/Dev/My Projects/Puzzle/main.m:13
Scheduled timer:
tGridTimer = [[CCTimer alloc] initWithTarget: self selector: #selector(gridSlideUpForced2:) interval: sGridSpeed];
[[CCScheduler sharedScheduler] scheduleTimer:tGridTimer];
Bit of CoCos 2d code that appears to be related to crashing:
-(void) tick: (ccTime) dt
{
if( timeScale_ != 1.0f )
dt *= timeScale_;
for( id k in methodsToRemove )
[scheduledMethods removeObject:k];
[methodsToRemove removeAllObjects];
for( id k in methodsToAdd )
[scheduledMethods addObject:k];
[methodsToAdd removeAllObjects];
for( CCTimer *t in scheduledMethods )
impMethod(t, fireSelector, dt);
[[CCScheduler sharedScheduler] scheduleTimer:tGridTimer];
Are you cleaning up your timers in onExit or dealloc in your scene class? Could be the scene still thinks some of the schedulers are still running
i get this error and EXC_BAD_ACESS when i run my maps application... any idea
#0 0x3510741c in objc_msgSend ()
#1 0x30a69364 in -[CLLocationManager onClientEventLocation:] ()
#2 0x30a66960 in -[CLLocationManager onClientEvent:supportInfo:] ()
#3 0x30a66b28 in OnClientEvent ()
#4 0x30a5f860 in CLClientInvokeCallback ()
#5 0x30a633e4 in CLClientHandleDaemonData ()
#6 0x357a902c in __CFMessagePortPerform ()
#7 0x3577be46 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ ()
#8 0x3577be04 in __CFRunLoopDoSource1 ()
#9 0x3576e0a4 in __CFRunLoopRun ()
#10 0x3576dd7a in CFRunLoopRunSpecific ()
#11 0x3576dc88 in CFRunLoopRunInMode ()
#12 0x336ace8c in GSEventRunModal ()
#13 0x318f0f94 in -[UIApplication _run] ()
#14 0x318ee4d4 in UIApplicationMain ()
#15 0x0000281c in main (argc=1, argv=0x2ffff5e0) at /Users/abcd/Desktop/wataproject/main.m:14
http://brainwashinc.wordpress.com/2010/01/05/mapkit-crash-getting-user-location/
This helped me solve this issue
#vivianaranha's approach might solve the issue but I believe (after encountering this myself) that you are doing something else bad.
Specifically, in my case I had set mapView.showsUserLocation = YES so under the hood mapView was wiring itself up to the CLLocationManager. The solution was to ensure that I called mapView.showsUserLocation = NO in viewWillDisappear.
Also I discovered that you must have mapView.userTrackingMode set to what you require before you make the call to mapView.showsUserLocation = YES. Putting it all together you end up with something like this:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.mapView.userTrackingMode = MKUserTrackingModeFollow;
self.mapView.showsUserLocation = YES;
self.mapView.delegate = self;
}
- (void)viewWillDisappear:(BOOL)animated {
self.mapView.userTrackingMode = MKUserTrackingModeNone;
self.mapView.showsUserLocation = NO;
self.mapView.delegate = nil;
[super viewWillDisappear:animated];
}
I have discovered that when my program starts, in one of my viewcontrollers the order of calling is viewDidAppear, viewWillAppear, viewDidAppear.
I was not expecting the first viewDidAppear to be called. What could be causing this and how do I fix it? ATM I have a flag in viewDiDAppear to check if viewWillAppear was called, but it's a hack.
The stacktrace (which is identical in bot calls to viewDidAppear)is:
#0 0x0000509e in -[MainView viewDidAppear:] at MainView.m:497
#1 0x3097e96e in -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]
#2 0x30af3abe in -[UINavigationTransitionView _notifyDelegateTransitionDidStopWithContext:]
#3 0x30af4930 in -[UINavigationTransitionView _navigationTransitionDidStop]
#4 0x3091af0d in -[UIViewAnimationState sendDelegateAnimationDidStop:finished:]
#5 0x3091ba9e in +[UIViewAnimationState popAnimationState]
#6 0x30af46fd in -[UINavigationTransitionView transition:fromView:toView:]
#7 0x30af3b01 in -[UINavigationTransitionView transition:toView:]
#8 0x30979f09 in -[UINavigationController _startDeferredTransitionIfNeeded]
#9 0x30a97d9c in -[UILayoutContainerView layoutSubviews]
#10 0x0040bd94 in -[CALayer layoutSublayers]
#11 0x0040bb55 in CALayerLayoutIfNeeded
#12 0x0040b3ae in CA::Context::commit_transaction
#13 0x0040b022 in CA::Transaction::commit
#14 0x308f942a in -[UIApplication _reportAppLaunchFinished]
#15 0x308fef33 in -[UIApplication handleEvent:withNewEvent:]
#16 0x308fad82 in -[UIApplication sendEvent:]
#17 0x309013e1 in _UIApplicationHandleEvent
#18 0x32046375 in PurpleEventCallback
#19 0x30245560 in CFRunLoopRunSpecific
#20 0x30244628 in CFRunLoopRunInMode
#21 0x308f930d in -[UIApplication _run]
#22 0x309021ee in UIApplicationMain
#23 0x00001e82 in main at main.m:14
I just ran into a very similar problem.
In my case, that was because of a bug from the ECSlidingViewController (https://github.com/edgecase/ECSlidingViewController).
I just updated the code from github, solved the problem.
Using a ECSlidingViewController, on top of the uikit navigationController, made the child's viewDidAppear called twice.
Put a break point in viewDidAppear, then inspect the call stack in the debugger. It will tell you what is calling the method.
When viewDidAppear is called, can you cancel another viewDidAppear in the event queue by following method ? Sometimes I use this to avoid some methods being called twice or more.
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:#selector(viewDidAppear) object:nil];
It's very likely that you want the behavior of viewDidLoad rather than viewDidAppear - viewDidAppear can be called multiple times by your ViewController when you're not expecting it to.
I see this log in the console when I run my app:
CALayer position contains NaN: [nan -0.5]
The app consists of a UITaBar of which the first tab is a UINavigationController. In the NavController I'm launching the AddressBookPicker. In the AddressBookPicker I'm only choosing to show phone numbers.
When I choose on a contact that has only email addresses, that is when I see this log.
I do not see any crashes or any issues for that matter, just the log printed onto the console. Want to make sure that this is not a hidden issue that crashes on me after the launch.
Below is a snippet of relevant code and the stacktrace. Not sure which other parts of the code to paste here, please let me know if there are any I can post that might help.
Any help/inputs appreciated.
Thanks!
Code
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
NSArray *displayedItems = [NSArray arrayWithObjects: [NSNumber numberWithInt:kABPersonPhoneProperty]), nil];
picker.displayedProperties = displayedItems;
picker.peoplePickerDelegate = self;
[self presentModalViewController:picker animated:YES];
Stacktrace
#0 0x00096377 in NSLog
#1 0x046b38c9 in CALayerSetPosition
#2 0x046b3846 in -[CALayer setPosition:]
#3 0x046b375f in -[CALayer setFrame:]
#4 0x002f510b in -[UIView(Geometry) setFrame:]
#5 0x003dbe6d in -[UILabel setFrame:]
#6 0x023ed095 in -[ABPersonTableViewDataSource reloadNoValueLabelAnimated:]
#7 0x0244cf53 in -[ABPersonTableViewDataSource reloadDataIncludingHeaderView:invalidatePropertyData:]
#8 0x023f30d4 in -[ABPersonTableViewDataSource reloadDataIncludingHeaderView:]
#9 0x023eabc9 in -[ABPersonViewControllerHelper prepareViewWithDisplayedProperties:person:allowActions:]
#10 0x023ea6bc in -[ABPersonViewControllerHelper loadViewWithDisplayedProperties:person:allowDeletion:allowActions:]
#11 0x023ea598 in -[ABPersonViewController loadView]
#12 0x0036a54f in -[UIViewController view]
#13 0x003689f4 in -[UIViewController contentScrollView]
#14 0x003787e2 in -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:]
#15 0x00376ea3 in -[UINavigationController _layoutViewController:]
#16 0x0037812d in -[UINavigationController _startTransition:fromViewController:toViewController:]
#17 0x00372ccd in -[UINavigationController _startDeferredTransitionIfNeeded]
#18 0x00379d8b in -[UINavigationController pushViewController:transition:forceImmediate:]
#19 0x00372b67 in -[UINavigationController pushViewController:animated:]
#20 0x02403bc2 in -[ABPeoplePickerNavigationController pushViewController:animated:]
#21 0x0242a424 in -[ABPeoplePickerNavigationController showCardForPerson:withMemberCell:animate:forceDisableEditing:personViewController:]
#22 0x0242ce20 in -[ABMembersViewController showCardForPerson:withMemberCell:animate:]
#23 0x0240a0ef in -[ABMembersController abDataSource:selectedPerson:atIndexPath:withMemberCell:animate:]
#24 0x023fdb47 in -[ABMembersDataSource tableView:didSelectRowAtIndexPath:]
#25 0x00333a48 in -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:]
#26 0x0032a32e in -[UITableView _userSelectRowAtIndexPath:]
#27 0x0003f21a in __NSFireDelayedPerform
#28 0x02631f73 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
#29 0x026335b4 in __CFRunLoopDoTimer
#30 0x0258fdd9 in __CFRunLoopRun
#31 0x0258f350 in CFRunLoopRunSpecific
#32 0x0258f271 in CFRunLoopRunInMode
#33 0x02f2f00c in GSEventRunModal
#34 0x02f2f0d1 in GSEventRun
#35 0x002ceaf2 in UIApplicationMain
#36 0x00002554 in main at main.m:14
This seems to now cause crashes in iOS 4.2. Try picking a contact with no phone number, you should go to a view that says No Phone numbers. The crash occurs when you go back to All Contacts then pick that contact again.
Is anyone else experiencing this problem?
edit: In my case, I am only displaying email addresses. Picking a contact without an email address twice causes the crash.
I'm having the same problem, though it doesn't appear to happen in the built in apps (eg. mail).
One slightly hackish workaround is to add the First and Last names to the list of displayed properties - it doesn't show the "no email address" layer in that case, but also doesn't crash.
I had the same problem with "CALayer position contains NaN:". The app was fine in iOS3.x and iOS4.1 devices, but crashed in iOS4.2.
In my case, I has the following code:
CGRect frame;
frame.size.height = kTableCellHeight - 11;
frame.size.width = widthCell - 30;
UILabel *descriptionLabel = [[UILabel alloc] initWithFrame:frame];
The UILabel creation failed and shown that error. In my case, it was solved adding arbitrary values for frame.origin (for this UILabel purpose, it didn't matter)
CGRect frame;
frame.size.height = kTableCellHeight - 11;
frame.size.width = widthCell - 30;
frame.origin.x = 0;
frame.origin.y = 0;
UILabel *descriptionLabel = [[UILabel alloc] initWithFrame:frame];
Maybe the problem with "CALayer position contains NaN" is because some nil, incomplete or undefined value or structure is being used.
I don't know.
I see this too - I am doing something completely different from you - I am using the route-me mapping engine to display scrollable maps.
I believe it has something to do with scrolling views - and a layer somehow involved in the scrolling. As some of the views you mentioned I believe are scrolling - this would concur with my observations.
I wish I had more data for you, but one thing I can tell you is that I have been working on the app for months, and have been testing it on the iPhone and iPad, devices and simulator, under OSes 3.2 and 4.0 - and have had no crashes or memory leaks [at all, or associated with this].
So in short - no idea - but I think you're okay!