UITableView覆盖/隐藏图像?

时间:2012-07-17 03:57:12

标签: iphone objective-c ios xcode uitableview

enter image description here

我希望在images之上设置2 tableView - 顶部一个image,视图底部一个image。就像在图片上。我在顶部tableView成功(当我滚动image时,它会在图片下滚动),但是,底部的tableView不会出现。 我做了什么,我只是调整了UIImageView's的大小并在顶部和底部缩短了它并添加了image。但在底部,没有CGRect flagsFrame = CGRectMake(0, 460, 320, 11); UIImageView *bottomFlags = [[UIImageView alloc]initWithFrame:flagsFrame]; bottomFlags.image = [UIImage imageNamed:@"flags_down"]; [self.view addSubview:bottomFlags]; [self.view bringSubviewToFront:bottomFlags]; 。我也尝试在代码中执行此操作:

tableView

但没有任何反应。为什么没有图片?看起来<UIWindow: 0x1be340; frame = (0 0; 320 480); layer = <UIWindowLayer: 0x1be430>> | <UILayoutContainerView: 0x1c0d00; frame = (0 0; 320 480); autoresize = W+H; layer = <CALayer: 0x1c0da0>> | | <UITransitionView: 0x1c1040; frame = (0 0; 320 431); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x1c1410>> | | | <UIViewControllerWrapperView: 0x1ca7a0; frame = (0 0; 320 431); autoresize = W+H; layer = <CALayer: 0x1ca0b0>> | | | | <UILayoutContainerView: 0x1c5bf0; frame = (0 0; 320 431); autoresize = W+H; layer = <CALayer: 0x1c5c40>> | | | | | <UINavigationTransitionView: 0x1c5fa0; frame = (0 0; 320 431); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x1c4da0>> | | | | | | <UIViewControllerWrapperView: 0x108ff0; frame = (0 64; 320 367); autoresize = W+H; layer = <CALayer: 0x109020>> | | | | | | | <UIView: 0x1d43f0; frame = (0 0; 320 367); autoresize = W+H; layer = <CALayer: 0x13bce0>> | | | | | | | | <UIImageView: 0x13bd10; frame = (0 0; 320 460); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x140fa0>> | | | | | | | | <UITableView: 0x9ec800; frame = (0 0; 320 367); clipsToBounds = YES; opaque = NO; autoresize = W+H; layer = <CALayer: 0x19cda0>; contentOffset: {0, 4165.5}> | | | | | | | | | <CustomCell: 0x10f5b0; baseClass = UITableViewCell; frame = (0 4097; 320 75); autoresize = W; layer = <CALayer: 0x10b1e0>> | | | | | | | | | | <UIGroupTableViewCellBackground: 0x10f510; frame = (9 0; 302 75); autoresize = W; layer = <CALayer: 0x13c330>> | | | | | | | | | | | <UIView: 0x19eae0; frame = (1 0; 300 1); hidden = YES; autoresize = W; layer = <CALayer: 0x125990>> | | | | | | | | | | | <UIView: 0x10e9b0; frame = (1 74; 300 1); hidden = YES; autoresize = W+TM; layer = <CALayer: 0x128fe0>> | | | | | | | | | | <UITableViewCellContentView: 0x10f6c0; frame = (10 0; 280 74); layer = <CALayer: 0x109620>> | | | | | | | | | | | <UIImageView: 0x115880; frame = (70 10; 350 25); userInteractionEnabled = NO; layer = <CALayer: 0x18d1e0>> | | | | | | | | | | | <UILabel: 0x13ba00; frame = (70 10; 230 25); text = 'Слиток'; clipsToBounds = YES; userInteractionEnabled = NO; layer = <CALayer: 0x117da0>> | | | | | | | | | | | <UILabel: 0x13eef0; frame = (70 40; 120 18); text = 'Бесценно'; clipsToBounds = YES; userInteractionEnabled = NO; layer = <CALayer: 0x126be0>> | | | | | | | | | | | <UIImageView: 0x10e350; frame = (10 10; 50 50); userInteractionEnabled = NO; layer = <CALayer: 0x117c30>> | | | | | | | | | | <UIButton: 0x109ab0; frame = (280 0; 30 74); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x10d080>> | | | | | | | | | | | <UIImageView: 0x191090; frame = (10 30; 10 13); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x11b880>> | | | | | | | | | | <UIView: 0x10e2e0; frame = (10 0; 300 1); layer = <CALayer: 0x10e310>> | | | | | | | | | <CustomCell: 0x1ca8b0; baseClass = UITableViewCell; frame = (0 4172; 320 75); autoresize = W; layer = <CALayer: 0x11cee0>> | | | | | | | | | | <UIGroupTableViewCellBackground: 0x11e610; frame = (9 0; 302 75); autoresize = W; layer = <CALayer: 0x1c5da0>> | | | | | | | | | | | <UIView: 0x1dd650; frame = (1 0; 300 1); hidden = YES; autoresize = W; layer = <CALayer: 0x11d140>> | | | | | | | | | | | <UIView: 0x117d50; frame = (1 74; 300 1); hidden = YES; autoresize = W+TM; layer = <CALayer: 0x143680>> | | | | | | | | | | <UITableViewCellContentView: 0x1183f0; frame = (10 0; 280 74); layer = <CALayer: 0x16e8a0>> | | | | | | | | | | | <UIImageView: 0x130740; frame = (70 10; 350 25); userInteractionEnabled = NO; layer = <CALayer: 0x10c170>> | | | | | | | | | | | <UILabel: 0x116b70; frame = (70 10; 230 25); text = 'Бонго'; clipsToBounds = YES; userInteractionEnabled = NO; layer = <CALayer: 0x10cc60>> | | | | | | | | | | | <UILabel: 0x115d80; frame = (70 40; 120 18); text = '$15 - $120'; clipsToBounds = YES; userInteractionEnabled = NO; layer = <CALayer: 0x115bb0>> | | | | | | | | | | | <UIImageView: 0x12e9c0; frame = (10 10; 50 50); userInteractionEnabled = NO; layer = <CALayer: 0x143620>> | | | | | | | | | | <UIButton: 0x11e580; frame = (280 0; 30 74); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x15a240>> | | | | | | | | | | | <UIImageView: 0x11f520; frame = (10 30; 10 13); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1dd1d0>> | | | | | | | | | | <UIView: 0x11e350; frame = (10 0; 300 1); layer = <CALayer: 0x118540>> | | | | | | | | | <CustomCell: 0x11c420; baseClass = UITableViewCell; frame = (0 4247; 320 75); autoresize = W; layer = <CALayer: 0x1912b0>> | | | | | | | | | | <UIGroupTableViewCellBackground: 0x112f10; frame = (9 0; 302 75); autoresize = W; layer = <CALayer: 0x11e230>> | | | | | | | | | | | <UIView: 0x117aa0; frame = (1 0; 300 1); hidden = YES; autoresize = W; layer = <CALayer: 0x109940>> | | | | | | | | | | | <UIView: 0x1decf0; frame = (1 74; 300 1); hidden = YES; autoresize = W+TM; layer = <CALayer: 0x123b60>> | | | | | | | | | | <UITableViewCellContentView: 0x115c60; frame = (10 0; 280 74); layer = <CALayer: 0x7275af0>> | | | | | | | | | | | <UIImageView: 0x10b7c0; frame = (70 10; 350 25); userInteractionEnabled = NO; layer = <CALayer: 0x101330>> | | | | | | | | | | | <UILabel: 0x128e70; frame = (70 10; 230 25); text = 'Кресло массажер'; clipsToBounds = YES; userInteractionEnabled = NO; layer = <CALayer: 0x117520>> | | | | | | | | | | | <UILabel: 0x10e3b0; frame = (70 40; 120 18); text = '$10 - $75'; clipsToBounds = YES; userInteractionEnabled = NO; layer = <CALayer: 0x104c50>> | | | | | | | | | | | <UIImageView: 0x18dc70; frame = (10 10; 50 50); userInteractionEnabled = NO; layer = <CALayer: 0x10f270>> | | | | | | | | | | <UIButton: 0x112e80; frame = (280 0; 30 74); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x11ceb0>> | | | | | | | | | | | <UIImageView: 0x111890; frame = (10 30; 10 13); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x11e6b0>> | | | | | | | | | | <UIView: 0x114480; frame = (10 0; 300 1); layer = <CALayer: 0x11d110>> | | | | | | | | | <CustomCell: 0x115fc0; baseClass = UITableViewCell; frame = (0 4322; 320 75); autoresize = W; layer = <CALayer: 0x125960>> | | | | | | | | | | <UIGroupTableViewCellBackground: 0x10ceb0; frame = (9 0; 302 75); autoresize = W; layer = <CALayer: 0x116220>> | | | | | | | | | | | <UIView: 0x11e280; frame = (1 0; 300 1); hidden = YES; autoresize = W; layer = <CALayer: 0x11e2b0>> | | | | | | | | | | | <UIView: 0x10edb0; frame = (1 74; 300 1); hidden = YES; autoresize = W+TM; layer = <CALayer: 0x10ede0>> | | | | | | | | | | <UITableViewCellContentView: 0x11c540; frame = (10 0; 280 74); layer = <CALayer: 0x1179a0>> | | | | | | | | | | | <UIImageView: 0x112940; frame = (70 10; 350 25); userInteractionEnabled = NO; layer = <CALayer: 0x10e530>> | | | | | | | | | | | <UILabel: 0x111090; frame = (70 10; 230 25); text = 'Громкоговоритель'; clipsToBounds = YES; userInteractionEnabled = NO; layer = <CALayer: 0x110a30>> | | | | | | | | | | | <UILabel: 0x1423c0; frame = (70 40; 120 18); text = '$10 - $75'; clipsToBounds = YES; userInteractionEnabled = NO; layer = <CALayer: 0x11c5a0>> | | | | | | | | | | | <UIImageView: 0x130880; frame = (10 10; 50 50); userInteractionEnabled = NO; layer = <CALayer: 0x11b8b0>> | | | | | | | | | | <UIButton: 0x10d650; frame = (280 0; 30 74); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1910f0>> | | | | | | | | | | | <UIImageView: 0x10a9a0; frame = (10 30; 10 13); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x10e4d0>> | | | | | | | | | | <UIView: 0x117a00; frame = (10 0; 300 1); layer = <CALayer: 0x117a30>> | | | | | | | | | <CustomCell: 0x12d010; baseClass = UITableViewCell; frame = (0 4397; 320 75); autoresize = W; layer = <CALayer: 0x123b30>> | | | | | | | | | | <UIGroupTableViewCellBackground: 0x111640; frame = (9 0; 302 75); autoresize = W; layer = <CALayer: 0x1f2260>> | | | | | | | | | | | <UIView: 0x1116a0; frame = (1 0; 300 1); hidden = YES; autoresize = W; layer = <CALayer: 0x10ebf0>> | | | | | | | | | | | <UIView: 0x10ec20; frame = (1 74; 300 1); hidden = YES; autoresize = W+TM; layer = <CALayer: 0x10ec50>> | | | | | | | | | | <UITableViewCellContentView: 0x10c100; frame = (10 0; 280 74); layer = <CALayer: 0x10f330>> | | | | | | | | | | | <UIImageView: 0x11b8e0; frame = (70 10; 350 25); userInteractionEnabled = NO; layer = <CALayer: 0x1185b0>> | | | | | | | | | | | <UILabel: 0x115f50; frame = (70 10; 230 25); text = 'Перочиный ножик'; clipsToBounds = YES; userInteractionEnabled = NO; layer = <CALayer: 0x109820>> | | | | | | | | | | | <UILabel: 0x115d10; frame = (70 40; 120 18); text = '$15 - $80'; clipsToBounds = YES; userInteractionEnabled = NO; layer = <CALayer: 0x1f22e0>> | | | | | | | | | | | <UIImageView: 0x112900; frame = (10 10; 50 50); userInteractionEnabled = NO; layer = <CALayer: 0x10ce80>> | | | | | | | | | | <UIButton: 0x10f470; frame = (280 0; 30 74); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1ca720>> | | | | | | | | | | | <UIImageView: 0x10dee0; frame = (10 30; 10 13); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x10df20>> | | | | | | | | | | <UIView: 0x1125d0; frame = (10 0; 300 1); layer = <CALayer: 0x118100>> | | | | | | | | | <CustomCell: 0x11c310; baseClass = UITableViewCell; frame = (0 4472; 320 75); autoresize = W; layer = <CALayer: 0x11ce00>> | | | | | | | | | | <UIGroupTableViewCellBackground: 0x10b580; frame = (9 0; 302 75); autoresize = W; layer = <CALayer: 0x155850>> | | | | | | | | | | | <UIView: 0x155880; frame = (1 0; 300 1); hidden = YES; autoresize = W; layer = <CALayer: 0x1128d0>> | | | | | | | | | | | <UIView: 0x10bb80; frame = (1 74; 300 1); hidden = YES; autoresize = W+TM; layer = <CALayer: 0x10bbb0>> | | | | | | | | | | <UITableViewCellContentView: 0x11cc70; frame = (10 0; 280 74); layer = <CALayer: 0x109b90>> | | | | | | | | | | | <UIImageView: 0x1dd5f0; frame = (70 10; 350 25); userInteractionEnabled = NO; layer = <CALayer: 0x1185e0>> | | | | | | | | | | | <UILabel: 0x115ca0; frame = (70 10; 230 25); text = 'Игровая консоль'; clipsToBounds = YES; userInteractionEnabled = NO; layer = <CALayer: 0x117c00>> | | | | | | | | | | | <UILabel: 0x162e10; frame = (70 40; 120 18); text = '$170 - $500'; clipsToBounds = YES; userInteractionEnabled = NO; layer = <CALayer: 0x10c140>> | | | | | | | | | | | <UIImageView: 0x10cc10; frame = (10 10; 50 50); userInteractionEnabled = NO; layer = <CALayer: 0x173d10>> | | | | | | | | | | <UIButton: 0x10bc90; frame = (280 0; 30 74); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x140a90>> | | | | | | | | | | | <UIImageView: 0x109360; frame = (10 30; 10 13); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x10f740>> | | | | | | | | | | <UIView: 0x118350; frame = (10 0; 300 1); layer = <CALayer: 0x118380>> | | | | | | | | | <UIImageView: 0x142450; frame = (0 360; 320 7); alpha = 0; opaque = NO; autoresize = TM; userInteractionEnabled = NO; layer = <CALayer: 0x15dc80>> | | | | | | | | | <UIImageView: 0x100b70; frame = (0 5608; 320 11); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x141f60>> | | | | | | | | | <UIImageView: 0x1d4d20; frame = (312 4427.5; 7 36); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = <CALayer: 0x1d4d80>> | | | | | | | | <UIImageView: 0x12ea90; frame = (0 0; 320 11); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x126aa0>> | | | | | | | | <UILabel: 0x124eb0; frame = (0 -135; 320 90); text = 'В комплекте подарите деву...'; clipsToBounds = YES; hidden = YES; userInteractionEnabled = NO; layer = <CALayer: 0x13ff90>> | | | | | | | | <UIImageView: 0x72763e0; frame = (126 -64; 64 64); hidden = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7275840>> | | | | | <UINavigationBar: 0x1c5c70; frame = (0 20; 320 44); autoresize = W; layer = <CALayer: 0x1c5d60>> | | | | | | <UINavigationBarBackground: 0x1c5f60; frame = (0 0; 320 44); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1c5ff0>> | | | | | | <UINavigationItemView: 0x1c17c0; frame = (116 8; 88 27); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1c1810>> | | | | | | <UINavigationItemButtonView: 0x1c1840; frame = (5 7; 80 30); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x109560>> | | <UITabBar: 0x1c0fe0; frame = (0 431; 320 49); autoresize = W+TM; layer = <CALayer: 0x1c10c0>> | | | <_UITabBarBackgroundView: 0x1c1290; frame = (0 0; 320 49); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1c1320>> | | | <UITabBarButton: 0x1c89e0; frame = (2 1; 103 48); opaque = NO; layer = <CALayer: 0x1c9be0>> | | | | <UITabBarSelectionIndicatorView: 0x1ca310; frame = (0 2; 103 44); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1ca3a0>> | | | | <UITabBarSwappableImageView: 0x1c9770; frame = (28 2; 48 32); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1c82c0>> | | | | <UITabBarButtonLabel: 0x1c9a40; frame = (27 34; 50 13); text = 'Giftopedia'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1c9b50>> | | | <UITabBarButton: 0x1ca9c0; frame = (109 1; 102 48); opaque = NO; layer = <CALayer: 0x1c0c00>> | | | | <UITabBarSwappableImageView: 0x1c96a0; frame = (27 2; 48 32); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1c9bb0>> | | | | <UITabBarButtonLabel: 0x1c8100; frame = (24 34; 55 13); text = 'Избранное'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1c9700>> | | | <UITabBarButton: 0x1ca4a0; frame = (215 1; 103 48); opaque = NO; layer = <CALayer: 0x1caff0>> | | | | <UITabBarSwappableImageView: 0x1c8830; frame = (27 2; 48 32); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1cb0c0>> | | | | <UITabBarButtonLabel: 0x1c8380; frame = (18 34; 66 13); text = 'Информация'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1bf790>> 涵盖图像或其他内容。

谢谢!

UPD:

{{1}}

3 个答案:

答案 0 :(得分:1)

查看recursiveDescription,我看到两个大小为320x11的UIImageView。一个是UITableView

的兄弟姐妹
<UIImageView: 0x12ea90; frame = (0 0; 320 11); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x126aa0>>

此图像视图的原点位于(0,0),因此我推断它是顶部图像视图。它在输出中的UITableView之后列出,这意味着它在堆叠顺序中位于表视图之上 - 它“更接近”用户的眼睛,并将绘制在表视图的顶部。

大小为320x11的其他图像视图被列为表视图的子视图:

<UIImageView: 0x100b70; frame = (0 5608; 320 11); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x141f60>>

因此在我看来,您将底部图像视图添加为表视图的子视图,但您需要将其添加为表视图的同级。您需要将其添加为表视图的超级视图的子视图。

答案 1 :(得分:1)

如果您希望图像保持在表格顶部

如果您想要将图像一致地放在UItableView上,那么将UITableView和两个页眉/页脚视图放在同一个UIView的子视图中,并将页眉/页脚视图放在前面。诀窍是关闭他们的userInteraction触摸它们到下面的UITableView

UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,460)];
[container addSubview:tableView];
[container addSubview:headerView];
[container addSubview:footerView];

headerView.userInteractionEnabled = NO;
footerView.userInteractionEnabled = NO;

如果您希望图像与表格一起滚动

您应该使用tableHeaderViewtableFooterView在UITableView实例的顶部和底部设置UIView。

答案 2 :(得分:0)

这一行似乎有点问题:

bottomFlags.image = [UIImage imageNamed:@"flags_down"];

尝试添加图片名称的扩展程序.png),否则image属性将为nil,您将看不到你一生中的形象。