I 자체 컨트롤러가있는 IKImageBrowserView를 참조 잃는다 다른 이미지를 추가하고 다른 클래스의 메서드를 호출하려면 결과가 없습니다. 나는 _imageBrowser가 참조를 잃어 버려서 아무 것도 아닌 것으로 나타났습니다.개체
어떻게이 문제를 해결할 수 있습니까?
AppDelegate.m
#import "AppDelegate.h"
#import "BrowserController.h"
@implementation AppDelegate{
BrowserController *imageBrowserController;
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
imageBrowserController = [BrowserController sharedManager];
}
- (IBAction)doSomething:(id)sender {
[imageBrowserController addMultipleImages];
}
@end
BrowserController.m 혼란은 당신이 당신의 질문과 그것의 시작 ImageBrowserController
을라고 언급 클래스의 이름으로이
#import "BrowserController.h"
@interface myImageObject : NSObject
{
NSString *_path;
}
@end
@implementation myImageObject
/* our datasource object is just a filepath representation */
- (void)setPath:(NSString *)path
{
if(_path != path)
{
_path = path;
}
}
/* required methods of the IKImageBrowserItem protocol */
#pragma mark -
#pragma mark item data source protocol
/* let the image browser knows we use a path representation */
- (NSString *)imageRepresentationType
{
return IKImageBrowserPathRepresentationType;
}
/* give our representation to the image browser */
- (id)imageRepresentation
{
return _path;
}
/* use the absolute filepath as identifier */
- (NSString *)imageUID
{
return _path;
}
@end
@interface BrowserController()
@end
@implementation BrowserController
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
}
return self;
}
- (void)drawRect:(NSRect)dirtyRect
{
[super drawRect:dirtyRect];
// Drawing code here.
}
- (void)awakeFromNib{
myImageObject *p;
p = [[myImageObject alloc]init];
[p setPath:[[NSBundle mainBundle]pathForResource:@"Unknown" ofType:@"jpg"]];
_images = [[NSMutableArray alloc]init];
[_images addObject:p];
[self updateDataSource];
}
- (void)updateDataSource{
[_imageBrowser reloadData];
}
-(NSUInteger) numberOfItemsInImageBrowser:(IKImageBrowserView *)aBrowser{
return [_images count];
};
-(id)imageBrowser:(IKImageBrowserView *)aBrowser itemAtIndex:(NSUInteger)index{
return [_images objectAtIndex:index];
};
- (void)updateDatasource
{
[_imageBrowser reloadData];
}
- (void)addMultipleImages{
myImageObject *p;
p = [[myImageObject alloc]init];
[p setPath:[[NSBundle mainBundle]pathForResource:@"Unknown" ofType:@"jpg"]];
_images = [[NSMutableArray alloc]init];
[_images addObject:p];
[_images addObject:p];
[_images addObject:p];
[_imageBrowser reloadData];
}
+ (id)sharedManager {
static BrowserController *sharedMyManager = nil;
@synchronized(self) {
if (sharedMyManager == nil)
sharedMyManager = [[self alloc] init];
}
return sharedMyManager;
}
@end
@property 자체에 중단 점을 넣고 nil로 설정할 수 있습니다. –
방금 시도했습니다. 앱이 처음로드 될 때 초기화시에만 중단 점을 중지합니다. – spacecash21
실제로 할당하고 시작 하시겠습니까? –