Question

I just started working with iOS7 in xCode and I'm trying to make a small app with a scroll view using xibs instead of storyboards. I created my project from the "empty" option and made a subclass of UIViewController called ViewController with .m,.h and .xib files. I added a UIScrollView into the xib and am trying to connect it with the correct property in the .h file, but it won't show up when I rightclick the scollview in the document outline. Any idea what's up?

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
Was it helpful?

Solution

You have a couple options.

A. Instead of right clicking the UIScrollView, right click on the File's Owner and you will see the IBOutlet you created there. Connect it to your UIScrollview in the xib.

B. Open Assistant Editor with the xib on one side and your .h on the other. Connect the UIScrollView and IBOutlet from one window to the other.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top