I have some code right now that can fill in a standard UITableView when set to 'Dynamic Prototypes'. I am loading these programmatically because I have a lot of rows and it gets confusing to detect which row was tapped. Here's the code I have so far:
PHP Code:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.villagersListing.count;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row % 2)
{
[cell setBackgroundColor:[UIColor colorWithRed:238.0f/255.0f green:244.0f/255.0f blue:244.0f/255.0f alpha:1.0]];
}
else [cell setBackgroundColor:[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0]];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleGray;
NSString *cellValue = [self.villagersListing objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
cell.textLabel.textColor = [UIColor colorWithRed:65.0f/255.0f green:65.0f/255.0f blue:65.0f/255.0f alpha:1.0];
return cell;
}
This pulls data from an NSMutableArray called
villagersListing and loads each string value into a UITableView. Towards the top I have
numberOfSectionsInTableView set to 1 because I don't actually need any sections.
The problem is that I'm trying to list out a set of fruits/vegetables in a different 'Crops' table view. I need 4 sections - Spring, Summer, Fall, and Winter - and each contain a different array of crops. Currently I have this working through manually entering values in Storyboard but I need to find a way to display them through Objective-C.
I'm hoping somebody can help me translate my above code to use a set of Sections instead of just one long list of rows.
Please let me know if I can clarify anything... Here is what my crops table looks like in Storyboard right now:
Spring[TABLE VIEW SECTION]- Turnip
- Potato
- Cucumber
- Cabbage
- Strawberry
Summer[TABLE VIEW SECTION]- Onion
- Tomato
- Corn
- Pineapple
- Pumpkin
- Pink Mist Flower
Fall[TABLE VIEW SECTION]- Carrot
- Eggplant
- Sweet Potato
- Green Pepper
- Breadfruit
- Spinach
- Magic Red Flower
Winter[TABLE VIEW SECTION]