Property 'images' not found on object of t

2019-04-17 15:31发布

I'm trying to merge these two projects.

Bearded - An iPhone photo app

Thumbnail Picker View

At this point I'm just trying to keep these in separate view controllers and getting the functionality of the Thumbnail Picker working in it's own controller.

I'm getting the error, as stated in the title, "Property 'images' not found on object of type 'UIViewController *'"

The error is coming from the AppDelegate.m file:

#import "AppDelegate.h"
#import "ViewController.h"

@implementation AppDelegate

@synthesize window = _window;
@synthesize viewController = _viewController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:    (NSDictionary *)launchOptions
{

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[UIViewController alloc] init];

NSArray *paths = [[NSBundle mainBundle] pathsForResourcesOfType:@"jpg" inDirectory:nil];
NSMutableArray *images = [NSMutableArray arrayWithCapacity:paths.count];
for (NSString *path in paths) {
    [images addObject:[UIImage imageWithContentsOfFile:path]];
}

self.viewController.images = images;
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];

return YES;
}


@end

Here is the AppDelegate.h:

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UIViewController *viewController;

@end

I've tried declaring a property like so:

@property (strong, nonatomic) UIImageView *images;

I can't seem to fix this even though I painstakingly merged these two codebases.

Here is the Xcode project of where I'm at at this point:

Xcode project

2条回答
我命由我不由天
2楼-- · 2019-04-17 15:53

I solved it. The problem was that I was merging a project using Storyboards and one that was using programmatically generated ViewController. Well, part of the problem.

Since, I merged the projects I had to give the view controller with the ThumbnailView another name. I named it ElfViewController.

This is the working code:

AppDelegate.h

#import <UIKit/UIKit.h>

@class ViewController;
@class ElfViewController;

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ElfViewController *viewController; // Changed here to ElfViewController
@property (strong, nonatomic) ViewController *firstViewController;

@end

AppDelegate.m

#import "AppDelegate.h"
#import "ViewController.h"
#import "ElfViewController.h"

@implementation AppDelegate

@synthesize window = _window;
@synthesize viewController = _viewController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:    (NSDictionary *)launchOptions
{

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ElfViewController alloc] init]; //Changed here to ElfViewController
self.firstViewController = [[ViewController alloc] init];

NSArray *paths = [[NSBundle mainBundle] pathsForResourcesOfType:@"jpg" inDirectory:nil];
NSMutableArray *images = [NSMutableArray arrayWithCapacity:paths.count];
for (NSString *path in paths) {
    [images addObject:[UIImage imageWithContentsOfFile:path]];
}

self.viewController.images = images;
self.window.rootViewController = self.firstViewController;
[self.window makeKeyAndVisible];

}

@end

I'm still new to Objective-C and have only learned how to create ViewControllers in Storyboard and not programmatically.

Also I didn't know that you can declare a property to a specific View Controller rather than just a general UIViewContoller. That's another place I got tripped up.

查看更多
萌系小妹纸
3楼-- · 2019-04-17 16:12

the "images" property you've declared in your .h file:

@property (strong, nonatomic) UIImageView *images;

is not the NSMutableArray you are trying to assign to it via this line:

self.viewController.images = images;

If you can get the types to be the same (i.e. either a single UIImageView object or a NSMutableArray containing many UIImages), then you should have better luck with assigning things to that property.

查看更多
登录 后发表回答