Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
Table View organization into Alphabetical sections
ok, onto my next dilemma. I've done a ton of Googling and it seems there are several ways to go about it, but none seem to fit my structuring of my table view. I'm using Xcode 4.3.2 with ARC and storyboards. I have a plain view table view. My table consists of a list of cities and their departments (one city for each row), when the user selects a city they will be pushed to a detail view of about that city. I want to organize my table alphabetically, with a section header. Any recommendations, hints, links to tutorials, would be greatly appreciated.
I have a NSMutable array set up like this in my table view .m
The section header can just be the letter of the alphabet (A, B, C, D...). I'm thinking I need to pre-organize my cities by their first letter and maybe name the section based on the letter (such as "sectionAcities"). The cities I have given are just a few, I have about 100 total.
Brian, thanks for that link on Clinging To Ideas. It looks like it is just what I need. However, when I tried it out it doesn't seem to work. Maybe it's because I am using xcode 4.3.2 with storyboards and ARC. I'm still pretty new at this, but how would I structure the
part of your code (I added in some of the data I need) to also include a phone number for each respective city, then be able to pass it to the next scene?
Pro tip: "It doesn't work" is probably the least useful phrase in programming. You need to be specific about what was expected, and how this compares to what actually happened. It also helps if you post code demonstrating what you have done.
Now then, I don't understand what you are asking for, as you seem to have a fine start there.
Let me try this instead. Take a look at this code here for my table view controller implementation file. My goal is to have the appropriate alphabet letter (the first letter of the city, for instance Albany would be in section A.) in a section header for my plain table view. This is just generic, the websites here are fake. When the user selects the row, it will bring them to the next screen where there will be a button linking them to the appropriate website. My real app will have phone numbers not websites, but obviously I can't test phone numbers in my simulator. Presently, my app works the way I want it to, I just want to add in section headers, so I am probably going to have to restructure my data. My question is, how can I incorporate your coding assistance, like I saw in your Clinging to Ideas blog into my already assembled data structure?
Could you show me an example of what my code should look like if I have the extra data, to pass over the website/phone number? I understand how to just display the alphabetized city names from your example, but I want to be able to pass the other info associated with that city.
Your model-object post is pretty cool and easy to follow. Except i am still not grasping how to incorporate my phone numbers/website into the data set to be displayed on the next view once a row is selected. Basically, I don't understand where I should be putting the phone number/website data in the array. Can you show me an example of how that would be arranged?
I don't see where you are even making an attempt to incorporate the items that I have described. Make an effort. I'm not going to write this code for you.
Still struggling here but I am seeing some progress. I've adapted some code that you recommended in your examples and I have gotten where I am now. This format will display and push the appropriate data, and display the section headers I want. However, it is not placing the appropriate city within the correct alphabetical section in my table. I am looking to find out how to do that. What I am thinking is that i need to place the
forKey:aKey]; forKey:bKey]; forKey:cKey];
somewhere. I tried to place it at the end of my [dept addObject:thedept]; line and the Cityname line, but those gave a error--Bad receiver type void.
There are links to 2 resources in my signature, and I have provided you with a 3rd. As far as I can tell, you are only using what was mentioned in one of them. So, reread the others, multiple times if necessary.
I believe I AM using your model object example to set up my data structure. I have successfully been able to complete all your training tutorials on Table Views as well. Now, I am just trying to incorporate the 'forKey:aKey'' part to link up the alphabetic letter to my row data (city name). But it seems no matter where I place it, I am getting an error stating "use of undeclared identifier 'forKey'"
My question now is, if I have my data set up as a model-object how do or where do I describe which section key each set goes into?
Replies
You might also get some use out of this: Clinging To Ideas: Taming Table Views
SlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI'm still pretty new at this, but how would I structure the
part of your code (I added in some of the data I need) to also include a phone number for each respective city, then be able to pass it to the next scene?
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeNow then, I don't understand what you are asking for, as you seem to have a fine start there.
SlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomePresently, my app works the way I want it to, I just want to add in section headers, so I am probably going to have to restructure my data.
My question is, how can I incorporate your coding assistance, like I saw in your Clinging to Ideas blog into my already assembled data structure?
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@\"ShowInfo\"]) {
InfoViewController *ivc = [segue destinationViewController];
NSIndexPath *path = [self.tableView indexPathForSelectedRow];
int row = [path row];
City *c = [dept objectAtIndex:row];
ivc.currentCity=c;
}
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
NSMutableArray *dept;
- (void)viewDidLoad
{
[super viewDidLoad];
dept = [[NSMutableArray alloc] init];
City *thedept = [[City alloc] init];
[thedept setCityname:@\"Akron\"];
[thedept setPhone:@\"www.youtube.com\"];
[dept addObject:thedept];
thedept = [[City alloc] init];
[thedept setCityname:@\"Albany\"];
[thedept setPhone:@\"www.yahoo.com\"];
[dept addObject:thedept];
thedept = [[City alloc] init];
[thedept setCityname:@\"Bridgeport\"];
[thedept setPhone:@\"www.yahoo.com\"];
[dept addObject:thedept];
thedept = [[City alloc] init];
[thedept setCityname:@\"Portland\"];
[thedept setPhone:@\"www.facebook.com\"];
[dept addObject:thedept];
thedept = [[City alloc] init];
[thedept setCityname:@\"Richmond\"];
[thedept setPhone:@\"www.myspace.com\"];
[dept addObject:thedept];
thedept = [[City alloc] init];
[thedept setCityname:@\"Springfield\"];
[thedept setPhone:@\"www.google.com\"];
[dept addObject:thedept];
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeSlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeSlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeSlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeSlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeHere is my code...
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeSlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeMy question now is, if I have my data set up as a model-object how do or where do I describe which section key each set goes into?
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeSlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeSlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome