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 > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 11-19-2011, 10:21 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2011
Location: Singapore
Posts: 6
Joseph83 is on a distinguished road
Default Passing the data from ParentController to ChildController

Anyone knows how to do the code let's say:

First select each row (UITableView) on ParentViewController and then it will push to another controller called ChildViewController which allows the user to select the choices. Upon selecting the choices, how to get this "choices" to be passed back to ParentViewController -> put this data on cell.detailTextLabel.text.

ChildViewController.m (didSelectRowAtIndexPath)
//Obtain the data
NSString *selectString = [countArray objectAtIndex: [indexPath row]];
NSLog(@"The answer is %@", selectString);

* It is able to show the correct value but I am wondering how will I pass it back to ParentViewController.

Hope to hear from you soon. Thanks.
Joseph83 is offline   Reply With Quote
Old 11-20-2011, 07:30 AM   #2 (permalink)
Registered Member
 
ebender001's Avatar
 
Join Date: Mar 2010
Location: Missouri
Age: 57
Posts: 70
ebender001 is on a distinguished road
Default

Quote:
Originally Posted by Joseph83 View Post
Anyone knows how to do the code let's say:

First select each row (UITableView) on ParentViewController and then it will push to another controller called ChildViewController which allows the user to select the choices. Upon selecting the choices, how to get this "choices" to be passed back to ParentViewController -> put this data on cell.detailTextLabel.text.

ChildViewController.m (didSelectRowAtIndexPath)
//Obtain the data
NSString *selectString = [countArray objectAtIndex: [indexPath row]];
NSLog(@"The answer is %@", selectString);

* It is able to show the correct value but I am wondering how will I pass it back to ParentViewController.

Hope to hear from you soon. Thanks.
Don't think about passing the value you chose back to the cell.detailTextLabel. Instead, think of how to alter your UITableView data source (of the parent's table), and then reload the tableview.

Ed
ebender001 is offline   Reply With Quote
Old 11-20-2011, 07:44 AM   #3 (permalink)
Registered Member
 
Join Date: Nov 2011
Location: Singapore
Posts: 6
Joseph83 is on a distinguished road
Default

Quote:
Originally Posted by ebender001 View Post
Don't think about passing the value you chose back to the cell.detailTextLabel. Instead, think of how to alter your UITableView data source (of the parent's table), and then reload the tableview.

Ed
Thanks for the reply but how will I alter my UITableView data source? Please advice. Thanks
Joseph83 is offline   Reply With Quote
Old 11-20-2011, 08:02 AM   #4 (permalink)
Registered Member
 
Join Date: Nov 2011
Location: Singapore
Posts: 6
Joseph83 is on a distinguished road
Default

I have added the codes for your reference and tell me what's wrong since you say I have to focus on ParentController only. ThirdViewController is actually a parentController while Quantity is actually a childController. Thanks for your great help I really appreciate.

tableNum is a name I declare for UITableCell. This code focus on how to redirect to child controller from parent controller.

Code:
//  ThirdViewController.m

// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
	[super loadView];
	
	tableNum = [[UITableView alloc] initWithFrame: [[UIScreen mainScreen] applicationFrame] style:UITableViewStyleGrouped];
	tableNum.delegate = self;
	tableNum.dataSource = self;
	tableNum.autoresizesSubviews = YES;
	
	dataArray = [[NSMutableArray alloc] init];
	[dataArray addObject: @"Quantity"];
	
	//self.view = tableNum;
}

// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
	if (section == 0)
	{ 
		return [dataArray count];
	}
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	
	static NSString *CellIdentifier = @"Cell";
	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
	
	if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
		
	}

	if (indexPath.section == 0)
	{
		NSString *cellValue = [dataArray objectAtIndex:indexPath.row];
		cell.textLabel.text = cellValue;
		cell.textLabel.textColor = [UIColor blackColor];
		cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
		cell.detailTextLabel.textColor = [UIColor blueColor];
		cell.detailTextLabel.text = @"";
		//cell.detailTextLabel.text = [self.countArray objectAtIndex:indexPath.row];
	}

return cell;
}

//for selecting which cell that goes to 2nd controller
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath {
	
	if (indexPath.section == 0)
	{
		if (self.qtyController == nil)
		{
			Quantity *viewTwo = [[Quantity alloc] initWithNibName:@"Quantity" bundle:[NSBundle mainBundle]];
			self.qtyController = viewTwo;
			[viewTwo release];
		}
		
		qtyController.title = [[NSString alloc] initWithFormat:@"Quantity"];
		[self.navigationController pushViewController:self.qtyController animated:YES];
}
Joseph83 is offline   Reply With Quote
Old 11-20-2011, 03:41 PM   #5 (permalink)
Registered Member
 
ebender001's Avatar
 
Join Date: Mar 2010
Location: Missouri
Age: 57
Posts: 70
ebender001 is on a distinguished road
Default

Quote:
Originally Posted by Joseph83 View Post
Thanks for the reply but how will I alter my UITableView data source? Please advice. Thanks
There are several ways to do this, but perhaps the most straightforward would be to pass a pointer to your parent when instantiating your child (initWithParent:self).
Then, you can send messages to the parent's tableview's datasource. You would need a mutable copy of the array backing the datasource, add whatever you chose in the child, and assigning that as the parent's tableview's datasource, and reloading the tableview of the parent.

Another way would be to use notifications.

Ed
ebender001 is offline   Reply With Quote
Old 11-22-2011, 08:23 PM   #6 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,002
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by Joseph83 View Post
Anyone knows how to do the code let's say:

First select each row (UITableView) on ParentViewController and then it will push to another controller called ChildViewController which allows the user to select the choices. Upon selecting the choices, how to get this "choices" to be passed back to ParentViewController -> put this data on cell.detailTextLabel.text.

ChildViewController.m (didSelectRowAtIndexPath)
//Obtain the data
NSString *selectString = [countArray objectAtIndex: [indexPath row]];
NSLog(@"The answer is %@", selectString);

* It is able to show the correct value but I am wondering how will I pass it back to ParentViewController.

Hope to hear from you soon. Thanks.
Why is this "How do I do basic communication between view controllers" post in the advanced discussion section? That's a bit like posting a "What colors of paint do I mix to get green" to an advanced oil painting forum.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 12-07-2011, 03:16 AM   #7 (permalink)
Registered Member
 
Join Date: Nov 2011
Location: Singapore
Posts: 6
Joseph83 is on a distinguished road
Default

Quote:
Originally Posted by Duncan C View Post
Why is this "How do I do basic communication between view controllers" post in the advanced discussion section? That's a bit like posting a "What colors of paint do I mix to get green" to an advanced oil painting forum.
Sorry for the late response. My apologies. Well, I have to switch to web application using Dashcode after hearing many feedbacks from my client regarding iPad development. He wants simple User Interface like including radio button or checkbox that allows displaying the list or hidding the list.

By the way, not sure if this forum is considered as Dashcode? In case, I will say it out if you know or not. Do you know why I am unable to view the iPad Simulator after running Dashcode? And do you know where I can enlarge the iPad size instead of iPhone size so I can build more user interface but I understand it is written in Java Script. Not sure if I should switch to Dashcode or Xcode but is it possible to have radio button and checkbox for visible or invisible on Xcode? If yes, I rather use Xcode because I am familar with it.

Please advise. Thanks.
Joseph83 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: 407
12 members and 395 guests
bignoggins, djqbert, epaga, flamingliquid, jcdevelopments, leighec68, LunarMoon, markolo, omagod, pinacate, revg, taylor202
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,645
Threads: 94,111
Posts: 402,861
Top Poster: BrianSlick (7,990)
Welcome to our newest member, leighec68
Powered by vBadvanced CMPS v3.1.0

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