将 UIButtons 添加到 ScrollView

发布于 2024-11-05 21:38:55 字数 1425 浏览 0 评论 0原文

我想在 ScrollView 框中显示 5 个按钮,但不幸的是我编写的代码对我的 UIButtons 没有影响(我无法向上或向下滚动,你能告诉我为什么吗?

谢谢你的帮助,我花了很多时间几个小时(菜鸟),但我仍然找不到解决方案...

我的代码:

FirstViewController.h:

#import <UIKit/UIKit.h>


@interface FirstViewController : UIViewController <UIScrollViewDelegate> {
IBOutlet UIScrollView *scroll;
UIButton *button;
UIButton *button2;
UIButton *button3;
}

@property (nonatomic, retain) IBOutlet UIButton *button;
@property (nonatomic, retain) IBOutlet UIButton *button2;
@property (nonatomic, retain) IBOutlet UIButton *button3;
@property(nonatomic,retain) IBOutlet UIScrollView *scroll;

@end

FirstViewController.m:

#import "FirstViewController.h"

@implementation FirstViewController
@synthesize button;
@synthesize button2;
@synthesize button3;
@synthesize scroll;


- (IBAction)goToViewTwo {
        }

- (void)viewDidload {
    [super viewDidLoad];
    [scroll setScrollEnabled:YES];
    [scroll setContentSize:CGSizeMake (500, 1000)];
}

- (void)dealloc {
    [super dealloc];
    [button release];
    [scroll release];
}                                      
@end

FirstView 中的层次结构。 xib:

View
  Action Sheet
  Text View
  ScrollView
    Button
    Button
    Button

关于插座:

  • 滚动视图通过“滚动”链接到文件的所有者
  • 视图作为“视图”链接到文件的所有者

I'd like to display 5 Buttons in a ScrollView Box but unfortunately the code I wrote has no effects on my UIButtons (I can't Scroll up or Down , can you tell me why ?

Thanks for you help, I spent a lot of hours on it (Rookie) but i still can't find the solution...

My Code :

FirstViewController.h :

#import <UIKit/UIKit.h>


@interface FirstViewController : UIViewController <UIScrollViewDelegate> {
IBOutlet UIScrollView *scroll;
UIButton *button;
UIButton *button2;
UIButton *button3;
}

@property (nonatomic, retain) IBOutlet UIButton *button;
@property (nonatomic, retain) IBOutlet UIButton *button2;
@property (nonatomic, retain) IBOutlet UIButton *button3;
@property(nonatomic,retain) IBOutlet UIScrollView *scroll;

@end

FirstViewController.m :

#import "FirstViewController.h"

@implementation FirstViewController
@synthesize button;
@synthesize button2;
@synthesize button3;
@synthesize scroll;


- (IBAction)goToViewTwo {
        }

- (void)viewDidload {
    [super viewDidLoad];
    [scroll setScrollEnabled:YES];
    [scroll setContentSize:CGSizeMake (500, 1000)];
}

- (void)dealloc {
    [super dealloc];
    [button release];
    [scroll release];
}                                      
@end

Hierarchy in FirstView.xib:

View
  Action Sheet
  Text View
  ScrollView
    Button
    Button
    Button

About the Outlets :

  • Scrollview is linked to File's Owner with "Scroll"
  • View is linked to File's Owner as a "view"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

贪恋 2024-11-12 21:38:55

我想您正在 Interface Builder 中实现滚动,并且该应用程序适用于 iPad(针对 contentSize)。看看IB和代码中是否有相同的配置,尤其是 [scroll setScrollEnabled:YES];

I suppose you're implementing the scroll in Interface Builder and that the app is for iPad (for the contentSize). See if you have the same configuration in IB and in code, especially that [scroll setScrollEnabled:YES];

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文