2011-08-25 4 views
0

iOS 앱을 처음 사용합니다. 현재 nib 파일을 변경하는 앱을 만들고 있습니다.iOS -h 파일에서 UIToolbar가 작동하지 않습니다.

그러나 XIB 사용자 인터페이스를 사용하여 새 UIViewController 하위 클래스를 만든 후에는 UIToolbar IBOutlet을 사용할 수 없습니다.

그것은 바보 같은 소리 수 있지만 "UIToolbar는"헤더 파일에서 보라색/분홍색 갈 나던 (.H) :

@property (nonatomic, retain) IBOutlet UIToolbar *toolbar; 

을도 아니다 "는 _toolbar"는에, 녹색/청색 이동하지 .m :

@synthesize toolbar = _toolbar; 

이것은 내가 UIToolbar를 사용하는 데 문제가되고 있습니다.

다음은 .H 내 코드입니다 :

#import <UIKit/UIKit.h> 

@interface pedestrians : UIViewController; 

@property (nonatomic, retain) IBOutlet UIToolbar *toolbar; 

@end 

그리고하는 .m을 위해 :

#import "pedestrians.h" 

@implementation pedestrians 

@synthesize toolbar = _toolbar; 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)didReceiveMemoryWarning 
{ 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 

#pragma mark - View lifecycle 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 
} 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return YES; 
} 

@end 

어떤 도움도 좋은 것입니다. 감사.

편집 :

그냥 (되지 않은 UI 물건을 따기)이 같은 UIBar 버튼을 추가하려고 : .m

+0

nib 파일에 IBOutlet 속성과 도구 모음을 연결 했습니까? –

+0

도구 모음 - 파일 소유자 - 예. – ryryan

답변

1

작성한 코드는 도구 모음과 관련하여 _toolbar라는 이름의 인스턴스 변수 (synthesize 문에서 가져옴)와 self.toolbar의 접근 자 두 가지를 작성했습니다. 그런 것이 없다면 "toolbar"라는 인스턴스 변수를 사용하려고합니다. _toolbar를 사용하거나 self.toolbar를 사용하십시오. 키 값 관측 기능을 유지하고 더 나은 상속 행위를 허용하므로 후자가 바람직합니다.

0

해당 파일에 toolbar을라는 이름의 인스턴스 변수가 없습니다. @property (nonatomic, retain) IBOutlet UIToolbar *toolbar;을 사용하면 인스턴스 변수가 작성되지 않습니다. viewDidLoad에 self.toolbar 또는 _toolbar에 액세스해야합니다.

+0

실제로 직접 ivar에 액세스하는 것과 반대로 코드에서'self.toolbar'를 사용하는 것이 바람직합니다. – Perception

+0

그는 .h에서 ivar을 생성하지 않고 있으며, @textbar를 사용하여 self.toolbar에 액세스하려고 함을 의미하는 @synthesize에 _toolbar를 지정하고 있습니다. – MishieMoo

+0

그는 현대 런타임을 사용하고 있습니다. ivar은 컴파일러에서 생성합니다. – Perception

-1

@interface 줄을 세미콜론으로 끝낼 수 있다고 생각하지 않습니다. 다음과 같은 .h 파일 코드를 변경할 수 있습니까

@interface pedestrians : UIViewController { 
} 
@property (nonatomic, retain) IBOutlet UIToolbar *toolbar; 
@end 
관련 문제