将 UIButtons 添加到 ScrollView
我想在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想您正在 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];