2010-08-23 6 views
1

UITabBarController의 하위보기 인 UIView 내에 프로그래밍 방식으로 사용자 지정 단추를 포함하려고했습니다. 버튼이 잘 표시되지만 클릭하면 오류 메시지없이 충돌합니다. 그 때때로 일관성 않는 이상한 : aboutView하지 심지어 내 재생 버튼 방식으로 코드를 제거하려클릭하면 UITabBarController의 UIButton이 충돌합니다!

 
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString playButton]: unrecognized selector sent to instance 0x632cd10' 

, 난, 나는 또한 "자기"에 직접 버튼을 추가하려고 playAction에 이름을 playButton 변경 시도 결과는 여전히 동일합니다.

제 생각에는 tabBar에 UIView가있는 버튼이있는 하위보기 인 것과 관련이 있습니다. 나는 모른다.

여기에 내가 내 AppDelegate에 방법



// About Tab 
aboutViewC = [[[AboutViewController alloc] init] autorelease]; 
aboutNavC = [[[UIViewController alloc] init] autorelease]; 
aboutNavC.title = @"About"; 
aboutNavC.view = aboutViewC.view; 

// Lessons Tab 
lessonsViewC = [[[LevelViewController alloc] init] autorelease]; 
lessonsViewC.title = @"Levels"; 
lessonsNavC = [[[UINavigationController alloc] initWithRootViewController:lessonsViewC] autorelease]; 
lessonsNavC.title = @"Lessons"; 
lessonsNavC.viewControllers = [NSArray arrayWithObjects:lessonsViewC, nil]; 

tabBarController = [[UITabBarController alloc] init]; 
tabBarController.viewControllers = [NSArray arrayWithObjects:aboutNavC, lessonsNavC, nil]; 

에 한 tabBar을 구축하는 방법의 코드와 AboutViewController 클래스

AboutViewController.h



#import 
@interface AboutViewController : UIViewController { 
UIButton *playSoundButton; 
UIView *aboutView; 
} 
- (void)playButton; 
@end 

AboutViewController을 구현을 heres 코드입니다. m


#import "AboutViewController.h" 

@implementation AboutViewController 

- (void)dealloc { 
    [playSoundButton release]; 
    [aboutView release]; 
    [super dealloc]; 
} 

- (void)viewDidLoad { 
aboutView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; 

[playSoundButton = [UIButton buttonWithType:UIButtonTypeCustom] retain]; 
image = [UIImage imageNamed:@"bt_play.png"]; 
[playSoundButton setImage:image forState:UIControlStateNormal]; 
[playSoundButton addTarget:self action:@selector(playButton) forControlEvents:UIControlEventTouchUpInside]; 
playSoundButton.frame = CGRectMake(0, 350, 40, 40); 
[aboutView addSubview:playSoundButton]; 

stopSoundButton.hidden = YES; 
playSoundButton.hidden = NO; 

[self.view addSubview:aboutView]; 

[super viewDidLoad]; 
} 

- (void)playButton 
{ 
NSLog(@"playAction method"); 
} 
@end 

미리 감사드립니다.

답변

0

감사 의견에 대한 TOB (UIButton에 대한 첫 번째 [ 더 오른쪽으로 이동 예), 실제로 문을 유지 구현하는 방법을 알고, 그것이 내가하지 않았다 오타

playSoundButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];했다 읽어야 주의. 놀랍게도, 그것은 문제가 아니며 오타를 변경하지 않고 코드를 실행해도 좋습니다.

실제 문제는 내 appDelegate 메소드에있었습니다. 대신

 
    // About Tab 
    aboutViewC = [[[AboutViewController alloc] init] autorelease]; aboutNavC = [[[UIViewController alloc] init] autorelease]; aboutNavC.title = @"About"; aboutNavC.view = aboutViewC.view; 
    // Lessons Tab 
    lessonsViewC = [[[LevelViewController alloc] init] autorelease]; 
    lessonsViewC.title = @"Levels"; 
    lessonsNavC = [[[UINavigationController alloc] initWithRootViewController:lessonsViewC] autorelease]; 
    lessonsNavC.title = @"Lessons"; 
    lessonsNavC.viewControllers = [NSArray arrayWithObjects:lessonsViewC, nil]; 
    tabBarController = [[UITabBarController alloc] init]; 
    tabBarController.viewControllers = [NSArray arrayWithObjects:aboutNavC, lessonsNavC, nil]; 
는해야
 
    // About Tab 
    aboutViewC = [[[AboutViewController alloc] init] autorelease]; 
    aboutViewC.title = @"About"; 
    // Lessons Tab 
    lessonsViewC = [[[LevelViewController alloc] init] autorelease]; 
    lessonsViewC.title = @"Levels"; 
    lessonsNavC = [[[UINavigationController alloc] initWithRootViewController:lessonsViewC] autorelease]; 
    lessonsNavC.title = @"Lessons"; 
    lessonsNavC.viewControllers = [NSArray arrayWithObjects:lessonsViewC, nil]; 
    tabBarController = [[UITabBarController alloc] init]; 
    tabBarController.viewControllers = [NSArray arrayWithObjects:aboutViewC, lessonsNavC, nil]; 

0

[playSoundButton = [UIButton buttonWithType:UIButtonTypeCustom] retain];

관련 문제