Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

shinta187

macrumors newbie
Original poster
Sep 27, 2010
11
0
Hi everybody,

Im new here, i recently started programming for the ipad/iphone.
Im trying to make an iPad Book Application.

I am using a simple button, i hooked everything up in IB, created outlets etc.

But when i click the button(setttings button upper right corner), the app crashes and it says, "unknown selector etc.."

It doesn't even get in the function. I don't even see my "NSLog(@"do something");"

I have selected my file owner in IB to my class (HomeView) where all my outlets are and my functions.

It's the same with the pageViewControls for my slider.
When i set the delegate to "self" and i click.. it crashes.

Below is my project for download. i commented the delegete out. since it crashes. (NDC2.zip)

Can anybody please help? It's driving me nuts for the past 2 days.

Thank You

http://www.mediafire.com/?3r02qifcxxz3ql7
 
When I downloaded it, it didn't have HomeView.xib in it. Couldn't compile
 
error message

Thanks for the quick reply,

Strange that homeview.xib is not included, i downloaded the file myself from mediafire and it is included.
============================================
The error is get is this:

2010-09-27 21:11:45.507 NDC2[1251:207] *** -[NSCFType doSomething:]: unrecognized selector sent to instance 0x4d15570

2010-09-27 21:11:45.509 NDC2[1251:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFType doSomething:]: unrecognized selector sent to instance 0x4d15570'

============================================

Can you try again? Thank you.
 
If this button was created in the navigation bar did you add a target/action for it.

If it wasn't and it's a button you created in IB then check your outlet.

Code:
-(IBAction)doSomething:(id)sender;
 
The button was created in IB, i don't have a navigationBar.

The outlet is my HomeView class .h (even though it doesn't need one )and in the .m is my function, i synthesized it and i connected the button in IB.

So i think the class is set up properly. tomorrow i will post the exact code.

thanks for the reply.
 
Here is the code.


AppDelegate.m i have

Code:
#import "AppDelegate_iPad.h"
#import "HomeView.h"

@implementation AppDelegate_iPad

#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
	
   	HomeView *homeview =[[HomeView alloc]
						 initWithNibName:@"HomeView"
						 bundle: nil];
	
	[window addSubview:homeview.view];
	[window makeKeyAndVisible];
	
	[homeview release];
	
	return YES;
}

In my HomeView.h i have:

Code:
#import <UIKit/UIKit.h>

@interface HomeView : UIViewController <UIScrollViewDelegate> {
	
	UIScrollView *scrollView;	
	UIPageControl *pageControl;
	UIButton *homeButton;
	UIButton *shopButton;
	UIButton *priceButton;
	UIButton *settingsButton;

	BOOL pageControlIsChangingPage;
}

@property (nonatomic, retain) IBOutlet UIScrollView *scrollView;
@property (nonatomic, retain) IBOutlet UIPageControl *pageControl;
@property (nonatomic, retain) IBOutlet UIButton *homeButton;
@property (nonatomic, retain) IBOutlet UIButton *shopButton;
@property (nonatomic, retain) IBOutlet UIButton *priceButton;
@property (nonatomic, retain) UIButton *settingsButton;

- (IBAction)changePage:(id)sender; //does not work
- (IBAction)doSomething:(id)sender; // does not work

@end

in my HomeView.m

Code:
#import "HomeView.h"


@implementation HomeView

@synthesize scrollView;
@synthesize pageControl;


///////////////////
//////Buttons//////
///////////////////

@synthesize homeButton;
@synthesize shopButton;
@synthesize priceButton;
@synthesize settingsButton;


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

	return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);	
}

#pragma mark -
#pragma mark UIView boilerplate
- (void)viewDidLoad 
{
	
    [super viewDidLoad];
	
	scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
	scrollView.clipsToBounds = YES;
	scrollView.scrollEnabled = YES;
	scrollView.pagingEnabled = NO;
	scrollView.showsVerticalScrollIndicator = NO;
	scrollView.showsHorizontalScrollIndicator = NO;
	
	//scrollView.delegate = self; 
	
	NSUInteger nimages = 0;
	CGFloat cx = 0;
	for (; ; nimages++) {
		NSString *imageName = [NSString stringWithFormat:@"book%d.png", (nimages + 1)];
		UIImage *image = [UIImage imageNamed:imageName];
		if (image == nil) {
			break;
		}
		UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
		
		CGRect rect = imageView.frame;
		rect.size.height = image.size.height;
		rect.size.width = image.size.width;
		rect.origin.x = ((scrollView.frame.size.width - image.size.width) /2) + cx;
		rect.origin.y = ((scrollView.frame.size.height - image.size.height) / 2);
		
		imageView.frame = rect;
		
		[scrollView addSubview:imageView];
		[imageView release];
		
		cx += scrollView.frame.size.width / 2;
	}
	
	self.pageControl.numberOfPages = nimages;
	[scrollView setContentSize:CGSizeMake(cx, [scrollView bounds].size.height)];
}

#pragma mark UIScrollViewDelegate stuff [B]// here it is going wrong[/B]
- (void)scrollViewDidScroll:(UIScrollView *)_scrollView
{
    if (pageControlIsChangingPage) {
        return;
    }
	

    CGFloat pageWidth = _scrollView.frame.size.width;
    int page = floor((_scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
    pageControl.currentPage = page;
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)_scrollView 
{
    pageControlIsChangingPage = YES;
}


#pragma mark -
#pragma mark PageControl stuff
- (IBAction)changePage:(id)sender 
{
    CGRect frame = scrollView.frame;
    frame.origin.x = frame.size.width * pageControl.currentPage;
    frame.origin.y = 0;
	
    [scrollView scrollRectToVisible:frame animated:YES];
	 
    pageControlIsChangingPage = YES;
}

- (IBAction)doSomething:(id)sender  // doesn't work
{
	NSLog(@"do something");
}



- (void)didReceiveMemoryWarning 
{
    [super didReceiveMemoryWarning];
}

- (void)viewDidUnload 
{
	[homeButton release];
	[shopButton release];
	[priceButton release];
	[settingsButton release];
}


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

@end



In my nib file (HomeView) i have my file owner at HomeView class, connected the button. but still crashes,

to sum it up:

I see my books in my slider. slider itself works except the pageControl.
when i want an action on one of the buttons is crashes. doesn't matter what i put in the function.

I hooked the settings button up in IB.

Thank's for the quick replies
 
In my nib file (HomeView) i have my file owner at HomeView class, connected the button. but still crashes...
Which button? You have four defined, one of which is not an IBOutlet.

Crashes how? Be specific. Are you still getting the run-time error you posted earlier? If not, what are you getting now? If nothing, have you checked the crash log?

Also, just a word of advice, if you're going to subclass UIViewController (which HomeView is), you should name it nameViewController so that it does not seem as though it is subclassed from UIView. Both of these classes are subclassed frequently (although UIViewController much more so), so better naming will help you and us to be less confused, hopefully.
 
Alright thanks for the tip.
==========================================
i just started a new universal project.
so all i got was 2 files AppDelegate_Ipad.h and AppDelegate_Ipad.m

then i added a new uiviewsubclass with a xib file.. (so 3 new files .h .m and a xib file)

then i began to work with it and added it to the window.
==========================================

The programs just crash with the same error i was getting before. so the simulator goes back to the homescreen.

I want the settingsButton to do something. so i connected it in IB, the rest of the buttons i just defined, i want to do something with them later.

If you can download the project you see what i mean.

thank you.
 
Yeah, seems to me that your settingsButton is being released before you can click on it to call doSomething:. But I can't, for the life of me, figure out why. Strange, indeed. Probably time to enable zombies.
 
That is what i was thinking as well.. that it's being releases before calling.

i can't figure it out :S.
 
hm,, when i remove the line "[homeView release]" in appDelegate_Ipad.m it works... the settingsButton gives me the output "Do Something".

strange....


Thanks for going through it with me.
 
ups..

confused the file with another..

it all makes sense now, i'm still new at this, so i'm trying my best.

thanks again.

(you must be thinking. "God, those Noobs...") :p thanks.
 
thanks again.
You're welcome.

(you must be thinking. "God, those Noobs...") :p
Actually, I was thinking: "Yay, they figured it out on their own!" I always feel that solving problems like this, where you come to your own discovery as to the cause only help to truly understand and stick in your memory for the next time something similar happens.
 
You got that right.

I will never forget this again :)

Anyway i can go on with my work now. If i have a problem. You'll be the first to know ;)

Have a great evening.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.