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-12-2010, 01:40 PM   #1 (permalink)
Awesome
 
Esko2300's Avatar
 
Join Date: Jun 2009
Location: New York, N.Y.
Posts: 389
Esko2300 is on a distinguished road
Default Wondering if this programming method is generally good to use

Ok well after my first iPhone application i really started to grasp the concept of the entire UIKit but one thing i still dont fully comprehend is using data from one view controller to the other. So i came up with my own little solution which is working fine for me right now but im wondering what your opinion would be upon my programming methods. Since i am parsing information and using information in other view controllers i decided to start using structs for a lot of the main data for each view controller. This to me makes it much more simple to pass around data from view controller to view controller, i even started placing my tableviews in the structs and assigning them to the table view in the nib file so i can be in another view controller and when needed i can manipulate the table view from the other view controller. So knowing this what do you think about this method?
Esko2300 is offline   Reply With Quote
Old 08-12-2010, 01:49 PM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

I guess I would need to see an example of what you are doing, because something sounds a little off about your explanation. Perhaps incorrect terminology.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 08-12-2010, 01:50 PM   #3 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

Sounds awful IMO
smithdale87 is offline   Reply With Quote
Old 08-12-2010, 02:06 PM   #4 (permalink)
Awesome
 
Esko2300's Avatar
 
Join Date: Jun 2009
Location: New York, N.Y.
Posts: 389
Esko2300 is on a distinguished road
Default

Well for me its working so idk i might stick with it unless one of you can relay to me why this would either break my program or get it sent back to me from apple.

But heres the portion of code and each view controller is exactly the same as the one im posting.

Code:
struct MyMenu {
	NSMutableArray *title;
	NSMutableArray *inventory;
	NSMutableArray *objectID;
	NSMutableArray *image;
	UITableView *tableView;
	bool userWantsMoreObjects;
	int thumbnailId;
	int overallCount;
	int pageCount;
	int count;
}myStruct;

@interface MyViewController : UITableViewController {

}

//ans heres the .m file
- (void)viewDidLoad {
    [super viewDidLoad];
	
	UIApplication *app = [UIApplication sharedApplication];
	app.networkActivityIndicatorVisible=FALSE;
	self.title=@"Objects";
	
	myStruct.tableView = self.tableView;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Override to allow orientations other than the default portrait orientation.
    return YES;
}

#pragma mark -
#pragma mark My Methods
//grabs more information from the server and adds it to the browse.tableView
-(void)grabMoreStructData{
	if(myStruct.overallCount==browse.count){
		UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Sorry"
													   message:@"There are no more objects left to get from server"
													  delegate:self
											 cancelButtonTitle:@"Ok"
											 otherButtonTitles:nil];
		[alert show];
		[alert release];
	}
	else{
		UIApplication *app = [UIApplication sharedApplication];
		app.networkActivityIndicatorVisible = TRUE;
	
		Struct.userWantsMoreObjects=TRUE;
		StructMenuData *bmd = [[StructMenuData alloc]init];
		[bmd parseMoreData];
		[bmd release];
	}
}
-(void)checkOverallCount{
//	if(Struct.overallCount==Struct.count)
//		self.navigationItem.rightBarButtonItem=nil;	
}
#pragma mark -
#pragma mark Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    // Return the number of rows in the section.
    return Struct.count;
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    NSInteger row = [indexPath row];
	
    CustomCell *cell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
	
    if (cell == nil) {
        cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease];
		
		UILabel *label = [[UILabel alloc]init];
		label.tag = objectTitleTag;
		
		label.textAlignment = UITextAlignmentLeft;
		[cell.contentView addSubview:label];
		[label release];
	}
	if(row==browse.count-1&&browse.count!=browse.overallCount){
		
		[cell.inventoryNumberLabel setFont:[UIFont boldSystemFontOfSize:15]];
		[cell.inventoryNumberLabel setFrame:CGRectMake(75, 20, 200, 20)];
		[cell.inventoryNumberLabel setText:@"Load More Objects..."];
		[cell.inventoryNumberLabel setTextColor:[UIColor blueColor]];
		[cell.contentView addSubview:cell.inventoryNumberLabel];
		
		[cell.artTitleLabel setText:[NSString stringWithFormat:@"You have %i Objects left",browse.overallCount-browse.count]];
		[cell.artTitleLabel setFrame:CGRectMake(75, 35, 200, 20)];
		cell.artTitleLabel.font = [UIFont boldSystemFontOfSize:10];
		cell.artTitleLabel.textColor = [UIColor grayColor];
		[cell.contentView addSubview:cell.artTitleLabel];
			
		cell.imageView.image=nil;
				
		
		return cell;
		[cell release];
	}
	else{
		[cell.inventoryNumberLabel setText:[browse.inventoryNumber objectAtIndex:row]];
		[cell.inventoryNumberLabel setTextColor:[UIColor blackColor]];
		[cell.inventoryNumberLabel setFont:[UIFont systemFontOfSize:18]];
		[cell.inventoryNumberLabel setFrame:CGRectMake(100, 5, 200, 20)];
		[cell.contentView addSubview:cell.inventoryNumberLabel];
		
		[cell.artTitleLabel setText:[browse.artTitle objectAtIndex:row]];
		[cell.artTitleLabel setFrame:CGRectMake(100, 25, 200, 20)];
		[cell.artTitleLabel setTextColor:[UIColor blackColor]];
		[cell.artTitleLabel setFont:[UIFont systemFontOfSize:15]];
		[cell.contentView addSubview:cell.artTitleLabel];	
		
		
		
		UIImage *theImage= [[UIImage alloc]initWithData:[browse.mainImageData  objectAtIndex:row]];
		cell.imageView.contentMode = UIViewContentModeScaleToFill;
		cell.imageView.image = theImage;
		[theImage release];
		
		return cell;
		[cell release];
	}		
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
	return 80;
}
#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
	UIApplication *app = [UIApplication sharedApplication];
	app.networkActivityIndicatorVisible = TRUE;
	
	if([indexPath row]==browse.count-1){
		[self grabMoreBrowseData];		
	}
	else {
		Struct.artObjectFromBrowse=TRUE;
		Struct.index=[indexPath row];
		getArtObjectParser = [[GetArtObjectParser alloc]init];
		[getArtObjectParser startParsing];
		
	}
	[self.tableView deselectRowAtIndexPath:indexPath animated:TRUE];
}
#pragma mark -
#pragma mark UIAlertView delegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
	self.navigationItem.rightBarButtonItem = nil;
}

#pragma mark -
#pragma mark Memory management

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Relinquish ownership any cached data, images, etc that aren't in use.
}
- (void)dealloc {
	getArtObjectParser=nil;
	Struct.tableView = nil;
	Struct.artTitle = nil;
	Struct.artObjectId = nil;
	Struct.mainImageData = nil;
	Struct.inventoryNumber = nil;
	
	[Struct.tableView release];
	[Struct.artTitle release];
	[Struct.artObjectId release];
	[Struct.mainImageData release];
	[Struct.inventoryNumber release];
	[getArtObjectParser release];
    [super dealloc];
}
Esko2300 is offline   Reply With Quote
Old 08-12-2010, 02:13 PM   #5 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

How does that allow you to share data in multiple view controllers? You would still need to pass the struct, right?

Considering the items that you have in the struct, seems it would be clearer to simply reuse a view controller with that structure.

I'm also going to guess that you have some memory management issues.

The table view in there is a curious choice. There really is no reason to be messing with user interface objects from/in other view controllers.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 08-12-2010, 02:31 PM   #6 (permalink)
Awesome
 
Esko2300's Avatar
 
Join Date: Jun 2009
Location: New York, N.Y.
Posts: 389
Esko2300 is on a distinguished road
Default

Well i ment to say i manip[ulate the table view from a parser which i created as an entirely new object, and i havent had any memory issues so far. Can you show me a short program about how to pass data from one view to another. Or should i just take a ViewController and send it as a parameter in a funciton.

But this is wherei get lazy, but heres what i mean, when you start a NSURLConnection you eventually get to the delegate methods, so at the connectionDidFinishLoading method i want to reload my tableview as needed so the only way i can think about accessing my tableview from within its view controller is to pass it to the first function i call to start the parsing. but then i would have to pass it to the connectionDidRecieveResponse method and then the connectionDidRecieveData and so on. This to me does not sound correct.
Esko2300 is offline   Reply With Quote
Old 08-12-2010, 02:37 PM   #7 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Well, some patterns you should research are:

1. Singletons.

2. Notifications.

3. Key-Value Observing


Duncan C has also recently made a post on data sharing:

http://www.iphonedevsdk.com/forum/ip...r-objects.html
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 08-12-2010, 02:39 PM   #8 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 138
wahness is on a distinguished road
Default

this looks to me like you are experimentally getting closer to the Model-View-Controller design pattern/architecture. this is the direction to go. but to be honest, you should really go there faster. and by faster, i mean you should look up model view controller, get a good solid understanding of it, and use it from now on. it will separate your views from your data and make it so that you can register as many views as you'd like. its usefulness and the clarity it will bring to your code are priceless.
wahness is offline   Reply With Quote
Old 08-12-2010, 03:19 PM   #9 (permalink)
Awesome
 
Esko2300's Avatar
 
Join Date: Jun 2009
Location: New York, N.Y.
Posts: 389
Esko2300 is on a distinguished road
Default

Thank you brian for the topics i should look up im going to look into that and thanks wahness for the advice and the support for a up and coming developer in need of assistance , ill look it up asap but do you know of any good sites explaining this topic other than the apple sdk site?
Esko2300 is offline   Reply With Quote
Reply

Bookmarks

Tags
parsing tableviews, structs, tableviews, viewcontroller

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: 356
5 members and 351 guests
bignoggins, Chickenrig, givensur, linkmx, PlutoPrime
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,894
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

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