오늘 :호출 SetNeedsDisplay 나는 새로운 문제에 직면하고있어
을 나는의 ViewController (NSView의의 서브 클래스)과 IBAction를 통해의 ViewController 다시 전화하려고, 다른 클래스 (NSObject의의 서브 클래스)가 SetNeedsDisplay : YES를 사용하여 뷰를 다시 그립니다.
(ViewController.m를)보기를 다시 그릴 수있는 방법은 다음과 같습니다
- (void) redrawView {
[self setNeedsDisplay:YES]
}
// With an NSLog i see that the method is called !
// Instead of self i tried even an outlet connected to the custom view.
}
내 다른 클래스를 통해의 ViewController 메서드를 호출하고있어 무엇은 다음과 같습니다
1) #import "ViewController.h"
2) IBAction에 ViewController의 새로운 기능을 다음과 같이 작성했습니다.
,451,515,ViewController *newIstanceOfViewController = [[ViewController alloc] init]
3)
로그 [newIstanceOfViewController redrawView]
여기에 원래 코드 (언어, 동일한 구문에 의한 방법의 다른 이름은)
// Controller.h
#import <Cocoa/Cocoa.h>
@interface Controller : NSView {
IBOutlet NSView *tastierinoView;
}
- (void) aggiornaTastierinoView;
@end
// Controller.m
#import "Controller.h"
@implementation Controller
//Contatore numero volte disegno view
int contatore = 0;
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
tastierinoView = [[NSView alloc] init];
}
return self;
}
- (void) aggiornaTastierinoView { //THIS IS THE METHOD TO CALL REDRAW
[tastierinoView setNeedsDisplay:YES];
NSLog(@"Chiamo setneedsDisplay\n\n");
}
- (void)drawRect:(NSRect)dirtyRect
{
contatore++;
NSLog(@"La view è stata disegnata %d volte\n\n",contatore);
[super drawRect:dirtyRect];
// Drawing code here.
NSBezierPath* percorso = [NSBezierPath bezierPath];
[[NSColor cyanColor] set];
[percorso moveToPoint:NSMakePoint(150, 150)];
[percorso lineToPoint:NSMakePoint(250, 150)];
[percorso setLineWidth:5.0];
[percorso stroke];
}
@end
// ManipolatorePin.h
#import <Foundation/Foundation.h>
@interface ManipolatorePin : NSObject {
IBOutlet NSWindow *finestraPrincipaleWindow;
IBOutlet NSTextField *codiceTextField;
NSArray *coordinate_x;
NSArray *coordinate_y;
//L'array sotto riportato serve, tramite un ciclo for, a salvare il codice pin spezzato in singoli numeri che corrisponderanno al punto.
NSMutableArray *numeroAllaIndexArray;
}
- (IBAction)aggiornaTastierino:(id)sender;
@end
// ManipolatorePin.m
#import "ManipolatorePin.h"
#import "Controller.h"
@implementation ManipolatorePin
- (void)awakeFromNib {
coordinate_x = [[NSArray alloc] initWithObjects:@"150",@"50",@"150",@"250",@"50",@"150",@"250",@"50",@"150",@"250", nil];
coordinate_y = [[NSArray alloc] initWithObjects:@"50",@"150",@"150",@"150",@"250",@"250",@"250",@"350",@"350",@"350", nil];
numeroAllaIndexArray = [[NSMutableArray alloc] init];
NSLog(@"Array coordinate iniziallizato.\nTest:(%@) -> deve risultare \"50\"\n\n",[coordinate_x objectAtIndex:4]);
}
- (IBAction)aggiornaTastierino:(id)sender {
NSString *codiceString = [[NSString alloc] initWithFormat:[NSString stringWithFormat:@"%@",[codiceTextField stringValue]]];
NSLog(@"codiceTextField = %@", codiceString);
int lunghezzaCodiceString;
NSLog(@"Il codice risulta essere composto da (%d) numeri\n\n",[codiceString length]);
//Svuoto array
[numeroAllaIndexArray removeAllObjects];
for (lunghezzaCodiceString = 0; lunghezzaCodiceString < [codiceString length]; lunghezzaCodiceString++) {
//Compilo array (Ci provo ahah)
NSString *carattereDelCodiceStringInEsame = [[NSString alloc] init];
carattereDelCodiceStringInEsame = [codiceString substringWithRange:NSMakeRange(lunghezzaCodiceString,1)];
NSLog(@"Aggiungo il numero (%@) all'array 'numeroAllaIndexArray'",carattereDelCodiceStringInEsame);
[numeroAllaIndexArray addObject:carattereDelCodiceStringInEsame];
}
//DEBUG - DA QUI IN POI E' CANCELLABILE
NSLog(@"\n\nCiclo for termitato\nProcesso concluso con successo\n\n\nContenuto array:");
int conteggioArray;
for (conteggioArray = 0; conteggioArray < [numeroAllaIndexArray count] ; conteggioArray++) {
NSLog(@"index (%d) -> (%@)",conteggioArray,[numeroAllaIndexArray objectAtIndex:conteggioArray]);
NSLog(@"\n\n");
}
//FINE DEBUG
///////////////HERE THE INSTANCE TO CALL THE CONTROLLER
Controller *istanzaGestionaleController = [[Controller alloc] init];
[istanzaGestionaleController aggiornaTastierinoView];
}
@end
문제를 해결하는 가장 좋은 방법은 무엇입니까? –
일부 예제 코드로 업데이트되었습니다. – bneely
감사합니다. 코코아에서 작동합니까? 나는 아이폰 OS에 있지 않다. 나는 myIstance.vc가 나에게 줄 것이다. Error –