gpt4 book ai didi

ios - 将 UIScrollView 连接到 IBOutlet

转载 作者:行者123 更新时间:2023-11-29 03:19:55 25 4
gpt4 key购买 nike

我刚开始在 xCode 中使用 iOS7,我正在尝试使用 xibs 而不是 Storyboard制作一个带有 ScrollView 的小型应用程序。我从“空”选项创建了我的项目,并创建了一个名为 ViewController 的 UIViewController 子类,其中包含 .m、.h 和 .xib 文件。我在 xib 中添加了一个 UIScrollView,并试图将它与 .h 文件中的正确属性连接起来,但是当我在文档大纲中右键单击 scollview 时,它不会显示。知道怎么回事吗?

应用委托(delegate):

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end


#import "AppDelegate.h"

#import "ViewController.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];

ViewController *view_controller = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = view_controller;

[self.window makeKeyAndVisible];
return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end

View Controller :

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController<UIScrollViewDelegate>



@property (strong, nonatomic) IBOutlet UIScrollView *scrollView;

@end


#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize scrollView;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

最佳答案

您有几个选择。

一个。不要右键单击 UIScrollView,而是右键单击“文件所有者”,您将看到您在其中创建的 IBOutlet。将其连接到 xib 中的 UIScrollview。

B.打开助理编辑器,一侧为 xib,另一侧为 .h。将 UIScrollView 和 IBOutlet 从一个窗口连接到另一个窗口。

关于ios - 将 UIScrollView 连接到 IBOutlet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21220670/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com