How to get first Cell of CollectionView? - swift
I want to change first cell's background color when Vc get notification. And I use the code like blow to achieve this, but it always get nil:
#objc func getNotification() {
let indexPath = IndexPath(row: 0, section: 0)
if let cell = collectionView.cellForItem(at: indexPath) as? TestCell {
cell.changeBackgroundColor()
}
}
and if I print visibelCells I got 6 different cell object!(It only show three on screen, and models.count also is 3), here is my log print visibleCells.
>>> visibleCells: <TestCell: 0x7fccbb6a5560; baseClass = UICollectionViewCell; frame = (58969.7 18.4; 353.7 115.2); transform = [0.90000000000000002, 0, 0, 0.90000000000000002, 0, 0]; alpha = 0.6; layer = <CALayer: 0x600000ccd9a0>>
>>> visibleCells: <TestCell: 0x7fccbb74c2b0; baseClass = UICollectionViewCell; frame = (58950 0; 393 128); layer = <CALayer: 0x600000cd8a20>>
>>> visibleCells: <TestCell: 0x7fccbe06c560; baseClass = UICollectionViewCell; frame = (58989.3 24.8; 314.4 102.4); transform = [0.80000000000000004, 0, 0, 0.80000000000000004, 0, 0]; alpha = 0.2; layer = <CALayer: 0x600000cdd3e0>>
>>> -----------------------
>>> visibleCells: <TestCell: 0x7fccbb6a5560; baseClass = UICollectionViewCell; frame = (58969.7 18.4; 353.7 115.2); transform = [0.90000000000000002, 0, 0, 0.90000000000000002, 0, 0]; alpha = 0.6; layer = <CALayer: 0x600000ccd9a0>>
>>> visibleCells: <TestCell: 0x7fccbb74c2b0; baseClass = UICollectionViewCell; frame = (58950 0; 393 128); layer = <CALayer: 0x600000cd8a20>>
>>> visibleCells: <TestCell: 0x7fccbe06c560; baseClass = UICollectionViewCell; frame = (58989.3 24.8; 314.4 102.4); transform = [0.80000000000000004, 0, 0, 0.80000000000000004, 0, 0]; alpha = 0.2; layer = <CALayer: 0x600000cdd3e0>>
>>> -----------------------
>>> visibleCells: <TestCell: 0x7fccbb6a5560; baseClass = UICollectionViewCell; frame = (59343 0; 393 128); layer = <CALayer: 0x600000ccd9a0>>
>>> visibleCells: <TestCell: 0x7fccbb663b90; baseClass = UICollectionViewCell; frame = (59382.3 24.8; 314.4 102.4); transform = [0.80000000000000004, 0, 0, 0.80000000000000004, 0, 0]; alpha = 0.2; layer = <CALayer: 0x600000cd6d40>>
>>> visibleCells: <TestCell: 0x7fccbe06c560; baseClass = UICollectionViewCell; frame = (59362.7 18.4; 353.7 115.2); transform = [0.90000000000000002, 0, 0, 0.90000000000000002, 0, 0]; alpha = 0.6; layer = <CALayer: 0x600000cdd3e0>>
>>> -----------------------
>>> visibleCells: <TestCell: 0x7fccbb74c2b0; baseClass = UICollectionViewCell; frame = (59775.3 24.8; 314.4 102.4); transform = [0.80000000000000004, 0, 0, 0.80000000000000004, 0, 0]; alpha = 0.2; layer = <CALayer: 0x600000cd8a20>>
>>> visibleCells: <TestCell: 0x7fccbb663b90; baseClass = UICollectionViewCell; frame = (59755.7 18.4; 353.7 115.2); transform = [0.90000000000000002, 0, 0, 0.90000000000000002, 0, 0]; alpha = 0.6; layer = <CALayer: 0x600000cd6d40>>
>>> visibleCells: <TestCell: 0x7fccbe06c560; baseClass = UICollectionViewCell; frame = (59736 0; 393 128); layer = <CALayer: 0x600000cdd3e0>>
>>> -----------------------
>>> visibleCells: <TestCell: 0x7fccbb55f6f0; baseClass = UICollectionViewCell; frame = (58969.7 18.4; 353.7 115.2); transform = [0.90000000000000002, 0, 0, 0.90000000000000002, 0, 0]; alpha = 0.6; layer = <CALayer: 0x600000cc84c0>>
>>> visibleCells: <TestCell: 0x7fccbb55a1e0; baseClass = UICollectionViewCell; frame = (58950 0; 393 128); layer = <CALayer: 0x600000d68000>>
>>> visibleCells: <TestCell: 0x7fccbe06c560; baseClass = UICollectionViewCell; frame = (58989.3 24.8; 314.4 102.4); transform = [0.80000000000000004, 0, 0, 0.80000000000000004, 0, 0]; alpha = 0.2; layer = <CALayer: 0x600000cdd3e0>>
>>> -----------------------
>>> visibleCells: <TestCell: 0x7fccbb55f6f0; baseClass = UICollectionViewCell; frame = (59343 0; 393 128); layer = <CALayer: 0x600000cc84c0>>
>>> visibleCells: <TestCell: 0x7fccbb6a5560; baseClass = UICollectionViewCell; frame = (59382.3 24.8; 314.4 102.4); transform = [0.80000000000000004, 0, 0, 0.80000000000000004, 0, 0]; alpha = 0.2; layer = <CALayer: 0x600000ccd9a0>>
>>> visibleCells: <TestCell: 0x7fccbe06c560; baseClass = UICollectionViewCell; frame = (59362.7 18.4; 353.7 115.2); transform = [0.90000000000000002, 0, 0, 0.90000000000000002, 0, 0]; alpha = 0.6; layer = <CALayer: 0x600000cdd3e0>>
>>> -----------------------
>>> visibleCells: <TestCell: 0x7fccbb55a1e0; baseClass = UICollectionViewCell; frame = (59775.3 24.8; 314.4 102.4); transform = [0.80000000000000004, 0, 0, 0.80000000000000004, 0, 0]; alpha = 0.2; layer = <CALayer: 0x600000d68000>>
>>> visibleCells: <TestCell: 0x7fccbb6a5560; baseClass = UICollectionViewCell; frame = (59755.7 18.4; 353.7 115.2); transform = [0.90000000000000002, 0, 0, 0.90000000000000002, 0, 0]; alpha = 0.6; layer = <CALayer: 0x600000ccd9a0>>
>>> visibleCells: <TestCell: 0x7fccbe06c560; baseClass = UICollectionViewCell; frame = (59736 0; 393 128); layer = <CALayer: 0x600000cdd3e0>>
>>> -----------------------
>>> visibleCells: <TestCell: 0x7fccbb663b90; baseClass = UICollectionViewCell; frame = (58969.7 18.4; 353.7 115.2); transform = [0.90000000000000002, 0, 0, 0.90000000000000002, 0, 0]; alpha = 0.6; layer = <CALayer: 0x600000cd6d40>>
>>> visibleCells: <TestCell: 0x7fccbb74c2b0; baseClass = UICollectionViewCell; frame = (58950 0; 393 128); layer = <CALayer: 0x600000cd8a20>>
>>> visibleCells: <TestCell: 0x7fccbe06c560; baseClass = UICollectionViewCell; frame = (58989.3 24.8; 314.4 102.4); transform = [0.80000000000000004, 0, 0, 0.80000000000000004, 0, 0]; alpha = 0.2; layer = <CALayer: 0x600000cdd3e0>>
>>> -----------------------
>>> visibleCells: <TestCell: 0x7fccbb663b90; baseClass = UICollectionViewCell; frame = (59343 0; 393 128); layer = <CALayer: 0x600000cd6d40>>
>>> visibleCells: <TestCell: 0x7fccbb55f6f0; baseClass = UICollectionViewCell; frame = (59382.3 24.8; 314.4 102.4); transform = [0.80000000000000004, 0, 0, 0.80000000000000004, 0, 0]; alpha = 0.2; layer = <CALayer: 0x600000cc84c0>>
>>> visibleCells: <TestCell: 0x7fccbe06c560; baseClass = UICollectionViewCell; frame = (59362.7 18.4; 353.7 115.2); transform = [0.90000000000000002, 0, 0, 0.90000000000000002, 0, 0]; alpha = 0.6; layer = <CALayer: 0x600000cdd3e0>>
>>> -----------------------
Your approach is wrong. Don't try to find a cell on screen and change the way it looks.
Update your collection view's model data when you get your notification, and then tell the collection view to reload the affected cell(s).
Related
UIView subviews not showing up
In my subclass of UIView (which I have instantiated in Interface Builder), has a couple buttons as subviews that I add to my view in the initWithCoder method like so: theButton = [UIButton buttonWithType:UIButtonTypeCustom]; [theButton setFrame:CGRectMake([UIScreen mainScreen].bounds.size.height-150-10, 289, 150, 21)]; [theButton.titleLabel setTextAlignment:UITextAlignmentRight]; [theButton setOpaque:YES]; [theButton.titleLabel setFont:[UIFont fontWithName:#"MyFont" size:32.0]]; [theButton.titleLabel setTextColor:[UIColor redColor]]; [theButton.titleLabel setText:#"text"]; [self addSubview:theButton]; [theButton addTarget:myTarget action:#selector(pause) forControlEvents:UIControlEventTouchUpInside]; But the button will not draw as it is supposed to. If I set a breakpoint in drawRect:, and po [self subviews] with llvm, I get this output. $0 = 0x0c93e860 <__NSArrayM 0xc93e860>( <UIButton: 0xc93d910; frame = (10 289; 150 21); alpha = 0.5; layer = <CALayer: 0xc93d4a0>>, <UIButton: 0xc93e2d0; frame = (408 289; 150 21); layer = <CALayer: 0xc93e390>> ) So why isn't my button showing up? Edit: my superview's recursiveDescription: <UIView: 0xa46b220; frame = (0 0; 320 568); transform = [0, -1, 1, 0, 0, 0]; autoresize = RM+BM; layer = <CALayer: 0xa46b280>> | <MyView: 0xa168710; frame = (0 0; 568 320); autoresize = W+H; layer = <CALayer: 0xa1687d0>> | | <UIButton: 0xa16c160; frame = (10 289; 150 21); alpha = 0.5; layer = <CALayer: 0xa16bcc0>> | | | <UIButtonLabel: 0xa16c3e0; frame = (0 0; 0 0); clipsToBounds = YES; hidden = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xa16c480>> | | <UIButton: 0xa16cb00; frame = (408 289; 150 21); layer = <CALayer: 0xa16cbc0>> | | | <UIButtonLabel: 0xa16c7e0; frame = (0 0; 0 0); clipsToBounds = YES; hidden = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xa16c880>>
Well, my guess is that your button is showing up, but you made it a custom button with no text for the normal state (and because you are not using any background image or color, it seems invisible). UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setTitle:#"Text" forState:UIControlStateNormal];
Instead of calling setText on the button's label, try sending setTitle:forState to the button (not its title label) instead: [theButton setTitle:#"text" forState:UIControlStateNormal]
UIButton is nil in MFMessageComposeController on iOS 6.0
I am trying to print the view hierarchy of the application's visible and hidden windows. Here is a part of my code inside a subclass of MFMessageComposeViewController: NSArray *windows = [[UIApplication sharedApplication] windows]; for(UIWindow *aWindow in windows) { if([aWindow isMemberOfClass:NSClassFromString(#"UITextEffectsWindow")]) { sendButton = [self findButtonInView:aWindow]; break; } } The findButtonInView: method is searching recursively a UIButton in the current UIWindow. This is working as expected when testing with iOS4.3 and iOS 5.1 (the expected UIButton is found successfully), but does not work with iOS6. Here are the results of the view hierarchy prints from both tests: iOS 4.3: <UITextEffectsWindow: 0x1e32a0; frame = (0 0; 320 480); opaque = NO; layer = <CALayer: 0x1e33d0>> | <UIPeripheralHostView: 0x1e4a80; frame = (0 224; 320 256); autoresizesSubviews = NO; layer = <UIPeripheralHostLayer: 0x1e4e60>> | | <UIKeyboardAutomatic: 0x1ad300; frame = (0 40; 320 216); opaque = NO; layer = <CALayer: 0x1ad3b0>> | | | <UIKeyboardImpl: 0x1ad520; frame = (0 0; 320 216); opaque = NO; layer = <CALayer: 0x1ad6c0>> | | | | <UIKeyboardLayoutStar: 0x1d47c0; frame = (0 0; 320 216); layer = <CALayer: 0x19ca40>> | | | | | <UIKBKeyplaneView: 0x1df880; frame = (0 0; 320 216); layer = <CALayer: 0x1df900>> | | | | | | <UIKBKeyView: 0x1dfe00; frame = (1 119; 40 42); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1dffd0>> | | | | | | <UIKBKeyView: 0x1e0090; frame = (279 119; 40 42); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1e00e0>> | | | | | | <UIKBKeyView: 0x1e01e0; frame = (1 173; 38 42); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1e0230>> | | | | | | <UIKBKeyView: 0x1dbfb0; frame = (41 173; 38 42); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1dc050>> | | | | | | <UIKBKeyView: 0x1e0330; frame = (81 173; 158 42); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1e0380>> | | | | | | <UIKBKeyView: 0x1e0440; frame = (241 173; 78 42); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1e0490>> | | <CKMessageEntryView: 0x182500; baseClass = UIImageView; frame = (0 0; 320 40); opaque = NO; autoresize = W+TM; layer = <CALayer: 0x1837c0>> | | | <UIButton: 0x1878c0; frame = (6 8; 26 27); hidden = YES; opaque = NO; autoresize = RM+TM; layer = <CALayer: 0x182e60>> | | | | <UIImageView: 0x1e56f0; frame = (0 0; 26 27); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1e5720>> | | | <UIView: 0x184dd0; frame = (7 0; 245 40); autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0x185130>> | | | <CKContentEntryView: 0x188a50; baseClass = UIScrollView; frame = (6 0; 249 40); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x187230>; contentOffset: {-0, -10}> | | | | <CKRichContentView: 0x193790; baseClass = UITextContentView; frame = (0 0; 249 20); text = ''; autoresize = W; layer = <CALayer: 0x1938a0>> | | | | | <UIWebDocumentView: 0xaef200; frame = (0 0; 249 20); text = ' '; opaque = NO; userInteractionEnabled = NO; layer = <UIWebLayer: 0x196c20>> | | | | | <UITextSelectionView: 0x1a5b60; frame = (0 0; 0 0); userInteractionEnabled = NO; layer = <CALayer: 0x1a5c00>> | | | | <UIImageView: 0x189fa0; frame = (242 10; 7 20); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = <CALayer: 0x189ff0>> | | | | <UIImageView: 0x189eb0; frame = (242 23; 7 7); alpha = 0; opaque = NO; autoresize = TM; userInteractionEnabled = NO; layer = <CALayer: 0x189f00>> | | | <UIImageView: 0x18a190; frame = (7 0; 245 40); opaque = NO; autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0x18a510>> | | | <UILabel: 0x18a6b0; frame = (245 13; 73 15); text = 'TEST'; clipsToBounds = YES; hidden = YES; opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = <CALayer: 0x18a720>> | | | <UIButton: 0x180d00; frame = (252 8; 61 27); opaque = NO; autoresize = LM+TM; layer = <CALayer: 0x184e00>> | | | | <UIImageView: 0x1ad460; frame = (0 0; 61 27); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1ad490>> | | | | <UIButtonLabel: 0x1871c0; frame = (11 3; 39 20); text = 'Send'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x187280>> iOS 6.0: <UIWindow: 0x1fd81f80; frame = (0 0; 320 480); opaque = NO; autoresize = RM+BM; layer = <UIWindowLayer: 0x1fd82080>> | <UILayoutContainerView: 0x1fd94d50; frame = (0 0; 320 480); autoresize = W+H; layer = <CALayer: 0x1fd94df0>> | | <UINavigationTransitionView: 0x1fd9a450; frame = (0 0; 320 480); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x1fd9a520>> | | | <UIViewControllerWrapperView: 0x1fdac9a0; frame = (0 20; 320 460); autoresize = W+H; layer = <CALayer: 0x1fdaca30>> | | | | <UIView: 0x1fda8cb0; frame = (0 0; 320 460); autoresize = W+H; layer = <CALayer: 0x1fda8c70>> | | | | | <_UISizeTrackingView: 0x1fda6430; frame = (0 0; 320 460); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x1fda6510>> | | | | | | <_UIRemoteView: 0x1fda6700; frame = (0 0; 320 480); transform = [0.5, -0, 0, 0.5, -0, 0]; userInteractionEnabled = NO; layer = <CALayerHost: 0x1fda6850>> My question is how the needed UIButton can be found inside UITextEffectsWindow? It seems that the view hierarchy in iOS6 is somehow changed... I would appreciate any help. Thanks!
It is likely that is it changed. You are accessing undocumented elements presented in the UI, which is not guaranteed to be consistent across system updates. If you would like to change the appearance of the UI elements presented in the MFMailComposeViewController class, use the IUAppearance API. You are not supposed to access much of the mail controller class. Important The mail composition interface itself is not customizable and must not be modified by your application. In addition, after presenting the interface, your application is not allowed to make further changes to the email content. The user may still edit the content using the interface, but programmatic changes are ignored. Thus, you must set the values of content fields before presenting the interface.
Removing a particular UIDatePicker subview
I have been working on uidatepicker view for a credit card option and I was curious if there would be any possibility to remove a particular view from subviews of UIDatePickerView? I iterated through the UIDatePickerView and got such contents: sub an views <UIView: 0x5bb55d0; frame = (0 0; 320 216); autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0x5bbaf00>> 2011-12-13 17:56:34.205 test[7615:207] sub an views <_UIOnePartImageView: 0x5bbbda0; frame = (20 86; 1 48); opaque = NO; autoresize = TM; userInteractionEnabled = NO; layer = <CALayer: 0x5bbbe20>> 2011-12-13 17:56:34.206 test[7615:207] sub an views <_UIPickerWheelView: 0x5bbd840; frame = (21 0; 150 216); autoresize = W+TM+H; userInteractionEnabled = NO; layer = <CALayer: 0x5bbd8c0>> 2011-12-13 17:56:34.207 test[7615:207] sub an views <_UIPickerViewSelectionBar: 0x5bbb430; frame = (21 86; 150 44); userInteractionEnabled = NO; layer = <CALayer: 0x5bbbdd0>> 2011-12-13 17:56:34.208 test[7615:207] sub an views <UIPickerTable: 0x5bbdd90; frame = (21 0; 146 216); clipsToBounds = YES; opaque = NO; autoresize = W+TM+H; layer = <CALayer: 0x5bbdcf0>> 2011-12-13 17:56:34.208 test[7615:207] sub an views <_UIOnePartImageView: 0x5bbbd60; frame = (21 0; 150 216); opaque = NO; autoresize = W+TM+H; userInteractionEnabled = NO; layer = <CALayer: 0x5bbd920>> 2011-12-13 17:56:34.209 test[7615:207] sub an views <_UIOnePartImageView: 0x5bbbf30; frame = (21 86; 150 62); opaque = NO; autoresize = W+TM+H; userInteractionEnabled = NO; layer = <CALayer: 0x5bbdfe0>> 2011-12-13 17:56:34.210 test[7615:207] sub an views <_UIOnePartImageView: 0x5bbe7f0; frame = (171 86; 2 48); opaque = NO; autoresize = TM; userInteractionEnabled = NO; layer = <CALayer: 0x5bbe820>> 2011-12-13 17:56:34.211 test[7615:207] sub an views <_UIPickerWheelView: 0x5bbe870; frame = (173 0; 48 216); autoresize = W+TM+H; userInteractionEnabled = NO; layer = <CALayer: 0x5bbe8a0>> 2011-12-13 17:56:34.212 test[7615:207] sub an views <_UIPickerViewSelectionBar: 0x5bbe8d0; frame = (173 86; 48 44); userInteractionEnabled = NO; layer = <CALayer: 0x5bbe900>> 2011-12-13 17:56:34.212 test[7615:207] sub an views <UIPickerTable: 0x5bbe930; frame = (173 0; 44 216); clipsToBounds = YES; opaque = NO; autoresize = W+TM+H; layer = <CALayer: 0x5bbeb10>> 2011-12-13 17:56:34.213 test[7615:207] sub an views <_UIOnePartImageView: 0x5bbec10; frame = (173 0; 48 216); opaque = NO; autoresize = W+TM+H; userInteractionEnabled = NO; layer = <CALayer: 0x5bbebe0>> 2011-12-13 17:56:34.214 test[7615:207] sub an views <_UIOnePartImageView: 0x5bbed90; frame = (173 86; 48 62); opaque = NO; autoresize = W+TM+H; userInteractionEnabled = NO; layer = <CALayer: 0x5bbedc0>> 2011-12-13 17:56:34.214 test[7615:207] sub an views <_UIOnePartImageView: 0x5bbee30; frame = (221 86; 2 48); opaque = NO; autoresize = TM; userInteractionEnabled = NO; layer = <CALayer: 0x5bbee60>> 2011-12-13 17:56:34.215 test[7615:207] sub an views <_UIPickerWheelView: 0x5bbee90; frame = (223 0; 76 216); autoresize = W+TM+H; userInteractionEnabled = NO; layer = <CALayer: 0x5bbeec0>> 2011-12-13 17:56:34.216 test[7615:207] sub an views <_UIPickerViewSelectionBar: 0x5bbeef0; frame = (223 86; 76 44); userInteractionEnabled = NO; layer = <CALayer: 0x5bbef20>> 2011-12-13 17:56:34.217 test[7615:207] sub an views <UIPickerTable: 0x5bbef50; frame = (223 0; 72 216); clipsToBounds = YES; opaque = NO; autoresize = W+TM+H; layer = <CALayer: 0x5bbf130>> 2011-12-13 17:56:34.217 test[7615:207] sub an views <_UIOnePartImageView: 0x5bbf1b0; frame = (223 0; 76 216); opaque = NO; autoresize = W+TM+H; userInteractionEnabled = NO; layer = <CALayer: 0x5bbf1e0>> 2011-12-13 17:56:34.218 test[7615:207] sub an views <_UIOnePartImageView: 0x5bbf2f0; frame = (223 86; 76 62); opaque = NO; autoresize = W+TM+H; userInteractionEnabled = NO; layer = <CALayer: 0x5bbf320>> 2011-12-13 17:56:34.219 test[7615:207] sub an views <_UIOnePartImageView: 0x5bbf3c0; frame = (299 86; 1 48); opaque = NO; autoresize = TM; userInteractionEnabled = NO; layer = <CALayer: 0x5bbf3f0>> 2011-12-13 17:56:34.220 test[7615:207] sub an views <_UIPickerViewTopFrame: 0x5bbb220; frame = (0 0; 320 216); opaque = NO; autoresize = W+H; layer = <CALayer: 0x5bbb460>> I am trying to remove the day view from the wheel, and I was curious if this approach might be some good way of removing a content as easy fix? Any other suggestion at this time will be good as well. Thanks
It might be easier to build your own UIPickerView instead of trying to remove sub-views from an UIDatePicker instance. see: UIDatePicker select Month and Year
Updating subviews of a UIScrollView without updating the scroll handle
Okay so I have a subclassed UIScrollView with some subviews inside it, when the device orientation changes I want to update the position of the subviews inside so that they fit the new orientation. When I just updated the positions of the subviews and then went to scroll I noticed that the scroll handle was ginormous... My loop that went through all of the subviews and updated their frames also set the frame of the scroll handle... So to get around this.. whenever I added subviews I set a tag on them. When the orientation changed I had a condition around my set frame which checked if the tag on the view matched the subviews I added. If yes then set the frame... int i = 0; for (UIView *gridViewItem in self.subviews) { if (gridViewItem.tag == GRID_CELL) { gridViewItem.frame = [self calculateCellPosition:i]; } i++; } But now I want to detect a touch on the subviews, and the easiest way I can think of doing that is by using the tag property so I know which subview is being tapped... However the tag is currently being used to help me distinguish the scroll handle from the other subviews... When i logged out the subviews of my UIScrollView I got this: 2011-05-08 16:07:56.266 XXXXXX[2096:207] ( "<UIView: 0x5a0d3f0; frame = (16 16; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a09250>>", "<UIView: 0x5a19d70; frame = (167 16; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a17660>>", "<UIView: 0x5a1d4f0; frame = (16 137; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a1d520>>", "<UIView: 0x5a1e300; frame = (167 137; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a1e330>>", "<UIView: 0x5a1e4f0; frame = (16 258; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a1e520>>", "<UIView: 0x5a1f320; frame = (167 258; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a1f350>>", "<UIView: 0x5a20120; frame = (16 379; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a20150>>", "<UIView: 0x5a20fb0; frame = (167 379; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a20fe0>>", "<UIView: 0x5a21dd0; frame = (16 500; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a21e00>>", "<UIView: 0x5a22bb0; frame = (167 500; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a22be0>>", "<UIView: 0x5a239a0; frame = (16 621; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a239d0>>", "<UIView: 0x5a247b0; frame = (167 621; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a247e0>>", "<UIView: 0x5a20f30; frame = (16 742; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a20f80>>", "<UIView: 0x5a26460; frame = (167 742; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a26490>>", "<UIView: 0x5a27220; frame = (16 863; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a27250>>", "<UIView: 0x5a20dd0; frame = (167 863; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a28080>>", "<UIView: 0x5a28e60; frame = (16 984; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a28e90>>", "<UIView: 0x5a29c50; frame = (167 984; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a29c80>>", "<UIView: 0x5a2aa60; frame = (16 1105; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a2aa90>>", "<UIView: 0x5a2b870; frame = (167 1105; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a2b8a0>>", "<UIView: 0x5a255a0; frame = (16 1226; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a255f0>>", "<UIView: 0x5a262f0; frame = (167 1226; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a2d610>>", "<UIView: 0x5a2e3c0; frame = (16 1347; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a2e3f0>>", "<UIView: 0x5a2f1d0; frame = (167 1347; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a2f200>>", "<UIView: 0x5a2ffc0; frame = (16 1468; 135 105); clipsToBounds = YES; tag = 1; layer = <CALayer: 0x5a2fff0>>" ) All of the subviews have my tag on it! I can't see the scroll handle? Does anyone know a way of identifying the scroll handle without using a tag like I have? Your help will be much appreciated! Thanks!
I probably wouldn't sub-class UIScrollView for this. Add a single UIView to UIScrollView and add your cells to that view. Then always work with that view. No need for tags and doesn't interfere with UIScrollViews inner workings. Scrolling should work as long as the size of your content view reflects the cells inside it.
Where Does A UIAlertView Live While Not Dismissed
Does anyone know in whose subview an active UIAlertView is located or how to find the thread in which it is running?
If you dump the contents of the windows property and all subviews of all views you can see that the UIAlertView is in a separate window that overlays the main window. Here I have a navbar with a viewcontroller and a tableview (I removed its subviews since they're not relevent). <UIWindow: 0x411fd50; frame = (0 0; 320 480); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x4120af0>> : <UILayoutContainerView: 0x4123310; frame = (0 0; 320 480); autoresize = W+H; layer = <CALayer: 0x411f800>> : | <UINavigationTransitionView: 0x4123500; frame = (0 0; 320 480); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x41232e0>> : | : <UIViewControllerWrapperView: 0x4519d30; frame = (0 64; 320 416); autoresize = W+H; layer = <CALayer: 0x4519a40>> : | : | <UITableView: 0x7808000; frame = (0 0; 320 416); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x45182a0>> : | <UINavigationBar: 0x45018b0; frame = (0 20; 320 44); clipsToBounds = YES; autoresize = W; layer = <CALayer: 0x4500fe0>> : | : <UINavigationItemView: 0x4522a20; frame = (100 8; 160 27); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x4526310>> : | : <UINavigationItemButtonView: 0x45230a0; frame = (5 7; 87 30); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x4520260>> <_UIAlertOverlayWindow: 0x4179b70; frame = (0 0; 320 480); opaque = NO; layer = <CALayer: 0x4188dc0>> : <UIAlertView: 0x4194bc0; frame = (3.8 161.95; 312.4 177.1); transform = [1.1, 0, 0, 1.1, 0, 0]; opaque = NO; animations = { transform=<CABasicAnimation: 0x4191160>; opacity=<CABasicAnimation: 0x41226f0>; }; layer = <CALayer: 0x4144c30>> : | <UILabel: 0x4177e70; frame = (12 15; 260 23); text = 'Name of Date'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x4179370>> : | <UILabel: 0x418b100; frame = (12 45; 260 41); text = 'Name of the date that you...'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x4128450>> : | <UIThreePartButton: 0x41942a0; frame = (11 102; 262 43); opaque = NO; tag = 1; layer = <CALayer: 0x4191f30>> Here is the code that produces the dump. I found it useful on occasion to see what is going on when something isn't doing what I expect: void dumpView(UIView* aView, NSString* indent) { if (aView) { NSLog(#"%#%#", indent, aView); // dump this view if (aView.subviews.count > 0) { NSString* subIndent = [[NSString alloc] initWithFormat:#"%#%#", indent, ([indent length]/2)%2==0 ? #"| " : #": "]; for (UIView* aSubview in aView.subviews) dumpView( aSubview, subIndent ); [subIndent release]; } } } void dumpWindows() { for (UIWindow* window in [UIApplication sharedApplication].windows) { dumpView(window, #"dumpView: "); } }
The active UIAlertView lives in a separate window (_UIAlertOverlayWindow). Use .windows property to find it. The whole UI runs in the main thread.
From the problem that you describe with windows and timing, sounds like you should implement alertView:didDismissWithButtonIndex:. You can trigger your followup code from within that method. EDIT: if that did not work, I'd try doing a delay to execute the FB stuff after a delay when the window is really guaranteed to be gone.