将UIScrollView连接到IBOutlet

时间:2014-01-19 18:16:51

标签: ios objective-c xcode uiscrollview iboutlet

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

的AppDelegate:

#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

的ViewController:

#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

1 个答案:

答案 0 :(得分:1)

你有两个选择。

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

B中。打开助手编辑器,一边是xib,另一边是.h。将UIScrollView和IBOutlet从一个窗口连接到另一个窗口。