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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.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 08-08-2010, 10:32 AM   #1 (permalink)
Registered Member
 
Join Date: Jun 2010
Location: Darlington UK
Posts: 84
kampftrinker is on a distinguished road
Default Using one view instead of seven

Hi, my app has eight views, one view has seven buttons each of these buttons opens another view when clicked. these views are all identical apart from the code to setup the array and the only different thing about that is the names for the images. The names for the images on the first view would be Grp1-1, Grp1-2, the names for the second view would be Grp2-1 and so on.


Code:
//set-up the array
	self.imgNamesArray = [NSArray arrayWithObjects:@"Grp7-1", @"Grp7-2", @"Grp7-3", @"Grp7-4", @"Grp7-5", @"Grp7-6", @"Grp7-7", @"Grp7-8", @"Grp7-9", @"Grp7-10", nil];
	NSString *strFirstImage = [[ivImgNamesArray objectAtIndex:ivCounter] stringByAppendingFormat:@".png"];
	UIImage *img = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:strFirstImage ofType:nil]];
	if (img != nil) {
		[ivImageView setImage:img];
	}
So my question is if i just had one view, how could i know which images to show depending on which button was pressed?

Thanks
Mick
kampftrinker is offline   Reply With Quote
Old 08-08-2010, 10:49 AM   #2 (permalink)
Fly-by-night Innovator
 
Join Date: Jun 2010
Posts: 364
musicwind95 is on a distinguished road
Default

Quote:
Originally Posted by kampftrinker View Post
Hi, my app has eight views, one view has seven buttons each of these buttons opens another view when clicked. these views are all identical apart from the code to setup the array and the only different thing about that is the names for the images. The names for the images on the first view would be Grp1-1, Grp1-2, the names for the second view would be Grp2-1 and so on.


Code:
//set-up the array
	self.imgNamesArray = [NSArray arrayWithObjects:@"Grp7-1", @"Grp7-2", @"Grp7-3", @"Grp7-4", @"Grp7-5", @"Grp7-6", @"Grp7-7", @"Grp7-8", @"Grp7-9", @"Grp7-10", nil];
	NSString *strFirstImage = [[ivImgNamesArray objectAtIndex:ivCounter] stringByAppendingFormat:@".png"];
	UIImage *img = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:strFirstImage ofType:nil]];
	if (img != nil) {
		[ivImageView setImage:img];
	}
So my question is if i just had one view, how could i know which images to show depending on which button was pressed?

Thanks
Mick
Tag the buttons, or set some kind of attribute/property. Then, use an (id)sender argument in the buttonPressed method, and check for the value of that tag or property.

- (IBAction)buttonPressed: (id)sender {
if (sender.number == 0)
[self loadView:view0];
else if (sender.number == 1)
[self loadView:view1];
...
}


You could also build an array of views, then enumerate through them...
musicwind95 is offline   Reply With Quote
Old 08-08-2010, 03:32 PM   #3 (permalink)
Registered Member
 
Join Date: Jun 2010
Location: Darlington UK
Posts: 84
kampftrinker is on a distinguished road
Default

Hi, thanks for the reply, what i ultimately want is to get rid of six of the seven similar views. The remaining view would load slightly different array depending on the button pressed so the code to decide this would be on the view to be opened so would this view be able to detect which button was pressed on a different view?

Thanks
Mick
kampftrinker is offline   Reply With Quote
Reply

Bookmarks

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
» Online Users: 313
9 members and 304 guests
arash5500, HemiMG, iram91419, linkmx, mediaspree, Objective Zero, Paul Slocum, stanny, Touchmint
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,656
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, iram91419
Powered by vBadvanced CMPS v3.1.0

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