Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 12-08-2009, 02:05 PM   #1 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Montreal, QC
Posts: 16
Unhappy Can't load button using subview

Howdy...

I'm having a problem trying to load a button using a subview.
What i would like is for my buttons to appear next to each other in rows and colums to be able to see all the photos (as buttons).

Here is where i load my viewController
Code:
- (void)viewDidLoad {
	[super viewDidLoad];
	
	UIButton *button;
	UIImage *thumbnail;	
	
	int images_count = self.photoCount;
	
	for (int i=0; i<=images_count-1; i++) {
		
		thumbnail = [thumbnails objectAtIndex:i];
				
		button = [UIButton buttonWithType:UIButtonTypeCustom];
		[button setImage:thumbnail forState:UIControlStateNormal];
		button.frame = CGRectMake(ThumbnailSizeWidth * (i % THUMBNAIL_COLS) + PADDING * (i % THUMBNAIL_COLS) + PADDING,
															ThumbnailSizeHeight * (i / THUMBNAIL_COLS) + PADDING * (i / THUMBNAIL_COLS) + PADDING + PADDING_TOP,
															ThumbnailSizeWidth,	ThumbnailSizeHeight);
		[self.scrollView addSubview:button];
	}
}
Using the debugger my for loop goes all the way throught the for loop and it seems to crash after the function who calls this view is done
Code:
- (void)showPhotoAlbum:(NSIndexPath *)indexPath {
	AlbumViewController *photoAlbum = [[AlbumViewController alloc] init];
	
	photoAlbum.thumbnails	= [thumbnails objectAtIndex:indexPath.row];
	photoAlbum.photos			=	[photos objectAtIndex:indexPath.row];
	photoAlbum.photoCount = [[numPhotos objectAtIndex:indexPath.row] intValue];
		
	photoAlbum.title = [title objectAtIndex:indexPath.row];
	[self.navigationController pushViewController:photoAlbum animated:YES];
	
	[photoAlbum release];
	[activityIndicator stopAnimating];
}
The error i am getting is
*** -[NSCFString size]: unrecognized selector sent to instance 0x4147b90
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString size]: unrecognized selector sent to instance 0x4147b90'

I've been looking into this error and dont understnd what it is refering to.
If someone could please help.

Forgot to mention... my nib file has a UISrcollView which is linked to the ScrollView in my ViewController. My mainview is of type UiScrollView, and is connected to the File's Owner

Last edited by simply07; 12-08-2009 at 02:10 PM.
simply07 is offline   Reply With Quote
Old 12-08-2009, 03:12 PM   #2 (permalink)
jsd
at this moment
 
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 900
Default

I don't see any calls to size in the code you posted, so it could be something the framework is trying to do. Set a breakpoint on objc_exception_throw - that will make the debugger stop on the exact line that is causing problems.
jsd is offline   Reply With Quote
Old 12-08-2009, 08:17 PM   #3 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Montreal, QC
Posts: 16
Default

Nor do i ever call size in anyway except when setting my buttons frame...
But I did what you suggested with the breakpoint (thanks, i didn't even know you could do that.... still kinda new to the sdk)

It stops not in my code but what i think is the ?machine code? .... BUT what i found that may be useful is that in the tread the last part I can make any sence of is "#5 0x0058b82d in -[UIButton imageRectForContentRect:]"

So could it be that the problem is because my images are too big for the frame i've set for the button? I've assumed that the button will resize the image to fit automatically!
simply07 is offline   Reply With Quote
Old 12-09-2009, 01:13 PM   #4 (permalink)
jsd
at this moment
 
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 900
Default

That's weird. It should break in your code, not the framework. What's the stack trace look like? Type 'bt' in the debug console and paste the results here.
jsd is offline   Reply With Quote
Old 12-09-2009, 02:16 PM   #5 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Montreal, QC
Posts: 16
Default

Here is the result:
Code:
(gdb) bt
#0  0x901b14d7 in objc_exception_throw ()
#1  0x0210583b in -[NSObject doesNotRecognizeSelector:] ()
#2  0x0209c676 in ___forwarding___ ()
#3  0x020786c2 in __forwarding_prep_0___ ()
#4  0x0058a82d in -[UIButton imageRectForContentRect:] ()
#5  0x005870d0 in -[UIButton(UIButtonInternal) _setupImageView] ()
#6  0x005875ab in -[UIButton layoutSubviews] ()
#7  0x0361b2b0 in -[CALayer layoutSublayers] ()
#8  0x0361b06f in CALayerLayoutIfNeeded ()
#9  0x0361a8c6 in CA::Context::commit_transaction ()
#10 0x0361a53a in CA::Transaction::commit ()
#11 0x03622838 in CA::Transaction::observer_callback ()
#12 0x02074252 in __CFRunLoopDoObservers ()
#13 0x0207365f in CFRunLoopRunSpecific ()
#14 0x02072c48 in CFRunLoopRunInMode ()
#15 0x0261e78d in GSEventRunModal ()
#16 0x0261e852 in GSEventRun ()
#17 0x003e0003 in UIApplicationMain ()
#18 0x0000224e in main (argc=1, argv=0xbffff0e4) at /Users/Steph/iPhone/PhotoAlbum/main.m:14
simply07 is offline   Reply With Quote
Old 12-09-2009, 02:32 PM   #6 (permalink)
jsd
at this moment
 
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 900
Default

I can't tell what's happening from the code you posted, but it looks like when it's exploding, it's because the button you think you have a reference to has been deallocated and replaced with a different kind of object. Are you releasing any UIButtons? Generally you don't want to do that because they are all obtained with buttonWith...
jsd is offline   Reply With Quote
Old 12-09-2009, 04:04 PM   #7 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Montreal, QC
Posts: 16
Default

No ... i create UIButton *button brefore my forloop and i set the button properties in that forloop...

But i think the problem lies within my nib file... I've been playing around with it and I'm gonna try to explain what does what and i'm sorry if it's confusing..

1.
My nib has is a UIScrollVIew within I have a Libray item of type UIScrollView which is declared as an IBOutlet of my .h

My File's Owner view is inked to the ViewController.
If i unlink my outlet, the program runs without crashing, but i dont see my buttons
If i link the outlet to either the ViewController or the library item it crashes

2. My nib is a UIView within I have a library item of type UIScrollView with is declared as an IBOulter in my .h

My File's Owner view is linked th the UIview of the ViewController
If I unlink my outlet the app runs without crashing, but still no buttons
If i link my outlet to the UIScrollView item the app crashes.

Also don't know if it makes a difference but this is my interface declaration on my .h
@interface AlbumViewController : UIViewController {
....
IBOutlet UIScrollView *scrollView;
}

I was wondering if this helps to know what the problem is! Is my nib improperly setup? Should I not be using the UIOutlet and just try to set up my buttons on the viewController? Sorry if i'm confusing...

Thanks again for all the help...

Last edited by simply07; 12-09-2009 at 04:47 PM.
simply07 is offline   Reply With Quote
Old 12-10-2009, 01:26 PM   #8 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Montreal, QC
Posts: 16
Default

Can anyone help?
I change my view bg to green and i can still see it...
but i've also added to labal to my scrollView to check that it wasn't invisible and i can see my label... :S
Can anyone help me....
I get my view but still can't seem to get the buttons to add as subviews
simply07 is offline   Reply With Quote
Old 12-10-2009, 01:29 PM   #9 (permalink)
jsd
at this moment
 
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 900
Default

I can't understand your description of what you're doing in your nib, but it sounds like that is the problem. Remove all the buttons and start over - add one at a time and test it each time until it starts crashing.
jsd is offline   Reply With Quote
Old 12-10-2009, 04:18 PM   #10 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Montreal, QC
Posts: 16
Smile

interesting...
I found the source of my problem..

I took your advice and rebuilt my nib from scratch... Now I'm creating my own UIScrollView within my code, (so no more IBOulet)...

The problem is that when setting the image for my button i was sending an NSSTring and not a UIImage... (tested while using an image within the application..

Now i just need to figure out how to set my NSString as an UIImage and my album view will be complete... (for some reason UIImage *thumbnail = (UIImage *)[thumbnails objectAtIndex:i]; isn't working in my forloop, yet it works in another part of my code!! maybe because it's a subview!!)

Thanks again for all the help..
simply07 is offline   Reply With Quote
Reply

Bookmarks

Tags
nscfstring, subviews, uibutton

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Stats
Members: 158,884
Threads: 89,229
Posts: 380,763
Top Poster: BrianSlick (7,129)
Welcome to our newest member, karlam963
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:17 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0