Note that there are some explanatory texts on larger screens.

plurals
  1. POUIButton in a UITabBarController crashing when clicked!
    primarykey
    data
    text
    <p>I tried to include a custom button programmatically inside a UIView which is a subview of UITabBarController. The button is displays fine but when I click it, it crashes without an error message. Its strange that sometimes it does inconsistently:</p> <pre> Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString playButton]: unrecognized selector sent to instance 0x632cd10' </pre> <p>I even tried removing any code in my play button method, i tried changing the name playButton to playAction, I also tried add the button directly to "self" not to aboutView but the result is still the same.</p> <p>My guess is it got something to do with the tabBar having a UIView as a subview with a button on it. I don't know.</p> <p>Here's a code snippet of how i built the tabBar in my appDelegate method</p> <pre><code> // 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]; </code></pre> <p>and heres the code for implementing the AboutViewController class</p> <p>AboutViewController.h</p> <pre><code> #import @interface AboutViewController : UIViewController { UIButton *playSoundButton; UIView *aboutView; } - (void)playButton; @end </code></pre> <p>AboutViewController.m</p> <pre><code> #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 </code></pre> <p>Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload