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 Tutorials > Tutorial Requests

Reply
 
LinkBack Thread Tools Display Modes
Old 02-04-2010, 01:00 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 10
Post Table View assistance please

Hello,

I'm new to this site, and the whole iphone dev scene! I've a problem and am requesting some help. Since I am new, there are many terms strategies I don't understand. If possible, talk to me like I'm 4!

My problem: I have a UITableView and when a cell is clicked, it opens another xib/viewController. I've set up a singleton to pass data from the table to the new view. But once the cell is tapped and new view opens, what ever was set in the singleton is the only thing that is set. If you push back and try a different cell, it will not change to that cell's value. I need the value, and not the key. Here are some snippets of my code:

table view view controller.m
- (NSIndexPath *)tableViewUITableView *)tableView willSelectRowAtIndexPathNSIndexPath *) indexPath {

// --- determine which anime was selected ---
NSUInteger section = [indexPath section];
NSUInteger row = [indexPath row];
NSString *key = [keys objectAtIndex:section];
NSArray *nameSelection = [info objectForKey:key];
NSString *selectedItem = [nameSelection objectAtIndex:row];

NameOfAppDelegate *mainDelegate = (NameOfAppDelegate *)[[UIApplication sharedApplication]delegate];
mainDelegate.sharedVar = selectedItem;



if (ViewController == nil) {
self.viewInfoViewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:[NSBundle mainBundle]];
}
[self presentModalViewController:self.ViewController animated:YES];

return indexPath;
}



detail view controller.m
List_o_AnimeAppDelegate *mainDelegate = (List_o_AnimeAppDelegate *)[[UIApplication sharedApplication]delegate];
NSString *viewBy = mainDelegate.sharedVar;

self.engTitle.text = viewBy;
[viewBy release];
viewBy = nil;



back button detail view controller.m
-(IBAction) barButtonBack {
[self dismissModalViewControllerAnimated:YES];
}




I've read articles, and tutorials from every corner of the web and I can't figure this one out. I'm not say the information is not out there. I'm just saying that I haven't found it yet, and don't know where to look.

Thanx!
tateyaku is offline   Reply With Quote
Old 02-04-2010, 02:25 PM   #2 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 74
Default

Quote:
Originally Posted by tateyaku View Post
Hello,

I'm new to this site, and the whole iphone dev scene! I've a problem and am requesting some help. Since I am new, there are many terms strategies I don't understand. If possible, talk to me like I'm 4!

My problem: I have a UITableView and when a cell is clicked, it opens another xib/viewController. I've set up a singleton to pass data from the table to the new view. But once the cell is tapped and new view opens, what ever was set in the singleton is the only thing that is set. If you push back and try a different cell, it will not change to that cell's value. I need the value, and not the key. Here are some snippets of my code:

table view view controller.m
- (NSIndexPath *)tableViewUITableView *)tableView willSelectRowAtIndexPathNSIndexPath *) indexPath {

// --- determine which anime was selected ---
NSUInteger section = [indexPath section];
NSUInteger row = [indexPath row];
NSString *key = [keys objectAtIndex:section];
NSArray *nameSelection = [info objectForKey:key];
NSString *selectedItem = [nameSelection objectAtIndex:row];

NameOfAppDelegate *mainDelegate = (NameOfAppDelegate *)[[UIApplication sharedApplication]delegate];
mainDelegate.sharedVar = selectedItem;



if (ViewController == nil) {
self.viewInfoViewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:[NSBundle mainBundle]];
}
[self presentModalViewController:self.ViewController animated:YES];

return indexPath;
}



detail view controller.m
List_o_AnimeAppDelegate *mainDelegate = (List_o_AnimeAppDelegate *)[[UIApplication sharedApplication]delegate];
NSString *viewBy = mainDelegate.sharedVar;

self.engTitle.text = viewBy;
[viewBy release];
viewBy = nil;



back button detail view controller.m
-(IBAction) barButtonBack {
[self dismissModalViewControllerAnimated:YES];
}




I've read articles, and tutorials from every corner of the web and I can't figure this one out. I'm not say the information is not out there. I'm just saying that I haven't found it yet, and don't know where to look.

Thanx!
Try this in your table view controrler inside the viewWillAppear method.

[self.tableView reloadData];
matt62king is offline   Reply With Quote
Old 02-04-2010, 03:49 PM   #3 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 10
Default Thanx

Thank you for the reply!

I've tried to put the viewWillLoad into my app, but it wouldn't work where ever I put it. I'm not using a navigation based program, it's just a normal view/VC with a table placed inside with interface builder.

I've tried putting the reloadData code in other places in the code, but still no effect. With and with out the self. section. I've even tried the release / = nil / reload /reloadData for the shared variable, but still no positive effects.

Do you, or any one else have any other way of implementing this code, or a different way of passing the selected value to the new view?
tateyaku is offline   Reply With Quote
Old 02-06-2010, 03:12 AM   #4 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 126
Default

Quote:
Originally Posted by tateyaku View Post
Thank you for the reply!

I've tried to put the viewWillLoad into my app, but it wouldn't work where ever I put it. I'm not using a navigation based program, it's just a normal view/VC with a table placed inside with interface builder.

I've tried putting the reloadData code in other places in the code, but still no effect. With and with out the self. section. I've even tried the release / = nil / reload /reloadData for the shared variable, but still no positive effects.

Do you, or any one else have any other way of implementing this code, or a different way of passing the selected value to the new view?
Well, viewWillLoad is never going to get called as it's not a valid method (unless I missed it in the documentation?). You can put it in viewDidLoad, but that will only update the data when the view is actually loaded. Try doing this:

Code:
-(void)viewWillAppear:(BOOL)animated {
    [self.tableView reloadData];
    [super viewWillAppear:animated];
}
So that every time the table view appears it will edit the data. I didn't test this because I don't have access to Xcode right now, so let me know what works and what doesn't and I'll try and help.
javaconvert is offline   Reply With Quote
Old 02-07-2010, 11:39 AM   #5 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 10
Default

I tried this code in several different spots in my app, but it says:

[self.tableView reloadData];
error: request for member 'tableView' in something not a structure or union
tateyaku is offline   Reply With Quote
Old 02-07-2010, 12:22 PM   #6 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 10
Default New information

Through the use of NSLog's I have found out that the table view is doing exactly what it should be doing. Reloading the table, passing the new selected row's value to the singleton and every thing else.

The part that is having the problem is the detail view after a cell is clicked. it's not refreshing the variable that holds the singleton's value. I have put viewWillAppear method in, and it lists a NSLog everytime. I have the methods to display the value received in the viewDidLoad method.


I apologize for the miss information. Being a newbie sucks.....

Last edited by tateyaku; 02-07-2010 at 12:24 PM.
tateyaku is offline   Reply With Quote
Old 02-07-2010, 12:31 PM   #7 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 10
Default Problem Fixed! YAY!!

I have found the answer! It may be a simple fix, or something that shouldn't have happened in the first place, but we all must start somewhere, and this is where I started, hehe.

I took the entire code out of the viewDidLoad method and placed it into viewWillAppear. This is probably a bad idea in itself, but for now the app works.

Any advice? Any thing to make my app work better/more efficient would be greatly appreciated
tateyaku is offline   Reply With Quote
Old 02-07-2010, 07:26 PM   #8 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Jan 2010
Location: Issaquah, WA
Age: 41
Posts: 1,184
Default

Quote:
Originally Posted by tateyaku View Post
I have found the answer! It may be a simple fix, or something that shouldn't have happened in the first place, but we all must start somewhere, and this is where I started, hehe.

I took the entire code out of the viewDidLoad method and placed it into viewWillAppear. This is probably a bad idea in itself, but for now the app works.

Any advice? Any thing to make my app work better/more efficient would be greatly appreciated
It's not a bad idea at all. viewDidLoad might only get called once during the whole run of your app. It's definitely not where you should be setting values based on table selections.
__________________
Recall It! Tag your notes. Tag your photos. Tag your thoughts. Tag your life.

Recall It! for iPad

http://www.dljeffery.com
dljeffery is offline   Reply With Quote
Reply

Bookmarks

Tags
data, singleton, uitableview, uitableviewcell, view

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: 244
13 members and 231 guests
2WeeksToGo, ADY, BrianSlick, Dani77, Dattee, headkaze, kapps11, mer10, mgon987, timle8n1, Touchmint, vigu360
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,879
Threads: 89,228
Posts: 380,745
Top Poster: BrianSlick (7,129)
Welcome to our newest member, mgon987
Powered by vBadvanced CMPS v3.1.0

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