How do I get from one table view to the other - ios

I'm a beginner at this and I'm trying to create an app in which you can select from several options. Therefore, I have a table view. Depending on which cell was tapped, another screen should appear with a second table view where I can checkmark things. Right now, I have one view controller in which I'm creating the first table view. How do I get to the second table view and how does it display the other array. Here is the code so far...
#interface ViewController (){
NSArray *genres;
NSArray *images;
NSMutableArray *array1;
NSMutableArray *array2;
NSMutableArray *array3;
}
#end
#implementation ViewController
#synthesize tableView;
(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title = #"Genres";
// Arrays must be in same order for image and title correspondance
genres = [[NSArray alloc] initWithObjects:
#"a1",
#"a2",
#"a3",
nil];
images = [[NSArray alloc] initWithObjects:
#"1.jpeg",
#"2.jpeg",
#"3.jpeg",
nil];
array1 = [[NSMutableArray alloc] initWithObjects:
#"1.1",
#"1.2",
#"1.3",
nil];
array2 = [[NSMutableArray alloc] initWithObjects:
#"2.1",
#"2.2",
#"2.3",
nil];
array3 = [[NSMutableArray alloc] initWithObjects:
#"3.1",
#"3.2",
#"3.3",
nil];
}
#pragma mark -
#pragma mark Table view data source
- (NSInteger) numberOfSectionsInTableView:(UITableView *) tableView{
return 1;
}
- (NSInteger) tableView:(UITableView *) tableView numberOfRowsInSection:(NSInteger)section{
return genres.count;
}
//Customize the apperance 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:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
}
//Configure Cell
cell.textLabel.text = [genres objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageNamed:[images objectAtIndex:indexPath.row]];
return cell;
}
#pragma mark -
#pragma mark Table view delegate
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSArray *selectedArray = [[NSArray alloc] init];
switch (indexPath.row) {
case 0:
selectedArray = array1;
break;
case 1:
selectedArray = array2;
break;
case 2:
selectedArray = array3;
break;
default:
break;
}
}

You can 1) create second view controller from code and set array like argument or 2) use segue interface:
Try to follow this complete answer:
https://stackoverflow.com/a/9736559/2429147
Also this link may be helpful regarding to work with segues and storyboards:
http://agilewarrior.wordpress.com/2012/01/25/how-segue-in-ios-and-pass-data-from-one-viewcontroller-to-another/

Related

Tableview data won't load when unsegmented control is changed

//The tableview is not changing. I have been at this for days. It seems so simple. Thank you for your help
#import "StopsTableViewController.h"
static NSString *MyIdentifier = #"RouteListing";
#interface StopsTableViewController ()
#property (strong, nonatomic) NSArray *TESTARRAY;
#end
#implementation StopsTableViewController
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
//Set the tab bar item's title
self.title = #"Stops";
}
self.stopList = [[API sharedAPI] fetchStopListing];
self.TESTARRAY = #[#"Josh", #"Kyle", #"Nate"];
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:MyIdentifier];
// Adds Segmented Control
[self segmentedView];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void) segmentedView {
NSArray *segmentedMenu = [NSArray arrayWithObjects:#"All", #"Near Me", nil];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:segmentedMenu];
[segmentedControl addTarget:self
action:#selector(valueChanged:)
forControlEvents:UIControlEventValueChanged];
segmentedControl.selectedSegmentIndex = 0;
self.navigationItem.titleView = segmentedControl;
}
pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if ([self.segmentedControl selectedSegmentIndex] == 0) {
return [self.stopList count];
}
else {
return [self.TESTARRAY count];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:MyIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
if (_segmentedControl.selectedSegmentIndex == 0) {
cell.textLabel.text = [[self.stopList objectAtIndex:indexPath.row] objectForKey:#"stoptitle"];
cell.detailTextLabel.text = [NSString stringWithFormat:#"Stop %#", [[self.stopList objectAtIndex:indexPath.row] objectForKey:#"stopnumber"]];
}
else {
cell.textLabel.text = self.TESTARRAY[indexPath.row];
}
return cell;
}
pragma mark - Table view delegate
// In a xib-based application, navigation from a table can be handled in -tableView:didSelectRowAtIndexPath:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here, for example:
// Create the next view controller.
StopInfoViewController *detailViewController = [[StopInfoViewController alloc] initWithNibName:#"StopInfoViewController" bundle:nil];
// Pass the selected object to the new view controller.
detailViewController.stopInfo = [[self.stopList objectAtIndex:indexPath.row] objectForKey:#"stopnumber"];
detailViewController.stopName = [[self.stopList objectAtIndex:indexPath.row] objectForKey:#"stoptitle"];
// Push the view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
}
//Function for segmentedView
-(void) valueChanged:(UISegmentedControl *)sender {
[self.tableView reloadData];
NSLog(#"I'm getting called segment number is: %ld", (long)sender.selectedSegmentIndex);
}
#end
Check your datasource array before calling the table reload method and make sure that the array contains new values corresponding to the segment that you have selected.
One thing I always run into when struggle up a table view is connecting the table with the interface using interface builder. Because it sounds like you're getting the data loaded, when the view first loads. But when you call [self.tableView reloadData] without having the connection made to the table, nothing will happen.
I ways forget that super simple step. Hope this helped
Did you set the tableview delegates?
Try putting this in your viewDidLoad function.
[tableView setDelegate:self];
[tableView setDataSource:self];
If you want a fuller explanation, check here:
how to set a tableview delegate
That post also explains how to ensure your class subscribes to the UITableViewDelegate and UITableViewDataSource protocols
Hope that helps.

iPhone Array with Dictionary with Array (ListApp)

I'm working on a list app. I have two arrays (Animals and Cars). The code looks like:
...
Edit:
This is the new code of the whole .m with your suggestions:
Now it works that everything is in one list. Now how to group them in the list?
#import "ListeViewController.h"
#interface ListeViewController ()
#end
#implementation ListeViewController{
NSArray *kategorien;
NSArray *autosArray;
NSArray *tiereArray;
NSArray *kategorienArray;
NSArray *combined;
NSDictionary *allgemein;
}
-(instancetype) initWithCoder:(NSCoder *)aDecoder{
self = [super initWithCoder:aDecoder];
if (self){
self->kategorien = #[#"Autos", #"Tiere"];
self->autosArray = #[#"Opel", #"Mercedes", #"Audi"];
self->tiereArray = #[#"Hamster", #"Ente", #"Schwan", #"Pferd", #"Pinguin"];
self->combined = [autosArray arrayByAddingObjectsFromArray:tiereArray];
self->allgemein = [NSDictionary dictionaryWithObjects: combined forKeys:combined];
}
return self;
}
-(instancetype) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self->kategorien = #[#"Autos", #"Tiere"];
self->autosArray = #[#"Opel", #"Mercedes", #"Audi"];
self->tiereArray = #[#"Hamster", #"Ente", #"Schwan", #"Pferd", #"Pinguin"];
self->combined = [autosArray arrayByAddingObjectsFromArray:tiereArray];
self->allgemein = [NSDictionary dictionaryWithObjects: combined forKeys:combined];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
#pragma mark -
#pragma mark Table view data source
-(NSInteger) numberOfSectionsInTableView:(UITableView*) tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *) tableView numberOfRowsInSection:(NSInteger)section{
return [combined 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:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
}
//Configure the Cell
cell.textLabel.text = [combined objectAtIndex:indexPath.row];
return cell;
}
#pragma mark -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(#"In did Select Row At Index Path");
NSLog(#"Row %d" ,indexPath.row);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
(sry or the german tagging of the arrays and the dictionary, also sry for some spelling and grammar)
You can use NSDictionary's dictionaryWithObjects:forKeys to create an NSDictionary based on two arrays.
The way you would do it would be:
self.allgemein = [NSDictionary dictionaryWithObjects:autosArray forKeys:tiereArray];
If you want to combine both arrays and then store them in a Dictionary with the same keys and objects (although why you would do this I'm not sure) then do:
NSArray *combined = [self.autosArray arrayByAddingObjectsFromArray:self.tiereArray];
self.allgemein = [NSDictionary dictionaryWithObjects:combined forKeys:combined];

How to show different view controller based on RowSelected in Tableviewcell?

I am new to iPhone Development and trying to create a small application(Recipe list) with multiple views. When the user selects one of the rows in tablecell, I would like to call a new view. For Instance, the menu card with items mushroom, pasta,steak must call another view with detailed recipe.
I have used UITableViewController to display a list of items with Accessory. These items are dynamically populated from a NSArray. When the user taps on one of the rows in the table, it should take him to a view controller based on the Row Selection. I know I have to implement tableView:didSelectRowAtIndexPath: function to call the appropriate view.
But I am not able to proceed. I read about Segue in storyboards, but even that seems a bit confusing for me.
I would really appreciate if someone solves my query. Here is my code.
RecipeViewController.h
#import "RecipeViewController.h"
#import "Recipe.h"
#interface RecipeViewController ()
#end
#implementation RecipeViewController
{
NSArray *recipes; //Recipe Array
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.title = #"Hotel";
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStyleBordered target:nil action:nil];
[[self navigationItem] setBackBarButtonItem:backButton];
// Create recipe array for main screen.
Recipe *recipe1 = [Recipe new];
recipe1.headline = #"Mushroom";
recipe1.description = #"description";
recipe1.imageFile = #"mushroom.jpg";
Recipe *recipe2 = [Recipe new];
recipe2.headline = #"pasta";
recipe2.description = #"Pasta description";
recipe2.imageFile = #"pasta.jpg";
Recipe *recipe3 = [Recipe new];
recipe3.headline = #"Steak";
recipe3.description = #"Steak description";
recipe3.imageFile = #"steak.jpg";
recipes = [NSArray arrayWithObjects:recipe1, recipe2, recipe3,nil];
// Remove table cell separator
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
// Assign custom backgroud for the view
self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"welcome_screen"]];
self.tableView.backgroundColor = [UIColor clearColor];
// Add padding to the top of the table view
UIEdgeInsets inset = UIEdgeInsetsMake(5, 0, 0, 0);
self.tableView.contentInset = inset;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#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 recipes.count;
}
- (UIImage *)cellBackgroundForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger rowCount = [self tableView:[self tableView] numberOfRowsInSection:0];
NSInteger rowIndex = indexPath.row;
UIImage *background = nil;
if (rowIndex == 0) {
background = [UIImage imageNamed:#"cell_top.png"];
} else if (rowIndex == rowCount - 1) {
background = [UIImage imageNamed:#"cell_bottom.png"];
} else {
background = [UIImage imageNamed:#"cell_middle.png"];
}
return background;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Display recipe in the table cell
Recipe *recipe = [recipes objectAtIndex:indexPath.row];
UIImageView *recipeImageView = (UIImageView *)[cell viewWithTag:100];
recipeImageView.image = [UIImage imageNamed:recipe.imageFile];
UILabel *recipeNameLabel = (UILabel *)[cell viewWithTag:101];
recipeNameLabel.text = recipe.headline;
UILabel *recipeDetailLabel = (UILabel *)[cell viewWithTag:102];
recipeDetailLabel.text = recipe.description;
// Assign our own background image for the cell
UIImage *background = [self cellBackgroundForRowAtIndexPath:indexPath];
UIImageView *cellBackgroundView = [[UIImageView alloc] initWithImage:background];
cellBackgroundView.image = background;
cell.backgroundView = cellBackgroundView;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
CampusViewController *campusViewController;
WhoViewController *whoViewController;
switch (indexPath.row)
{
case 0:
campusViewController=[[CampusViewController alloc] init];
[[self navigationController] pushViewController:campusViewController animated:YES];
break;
case 1:
whoViewController=[[WhoViewController alloc] init]; // not released as ARC is included in the project
[[self navigationController] pushViewController:whoViewController animated:YES];
break;
case 2:
break;
case 3:
break;
default:
break;
}
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"ShowDetails"]) {
RecipeViewController *detailViewController = [segue destinationViewController];
NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
/* NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
detailViewController.data = [self.dataController objectInListAtIndex:indexPath.row];
*/
}
}
#end
// Recipe.h
#import <Foundation/Foundation.h>
#interface Recipe : NSObject
#property (nonatomic, strong) NSString *headline; // name of recipe
#property (nonatomic, strong) NSString *description; // recipe detail
#property (nonatomic, strong) NSString *imageFile; // image filename of recipe
#end
Have you read any tutorials on how to do this? This is a very basic question and there are a lot of posts about this out there.
I'll only give you an explanation on how to do it but you will have to code it yourself.
The standard way we go about an application that shows the user different view controllers based on the selection of a UITableViewCell is by using a UINavigatorController. This controller gives you the methods:
– pushViewController:animated:
– popViewControllerAnimated:
... among others. With these two methods you can go back and forth between view controllers, which is what you want to do. So you have to give your navigator controller the table view controller that you already have. You can do that by using UINavigatorController's method – initWithRootViewController:
A little example of what your – tableView:willSelectRowAtIndexPath: might look like is:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIViewController *myViewController = [[UIViewController alloc] initWithNibName:#"YourNibName" bundle:nil];
self.navigationController pushViewController:[myViewController autorelease] animated:YES];
}
Hope this helps!
Further reading:
UINavigationController tutorial Ray Wenderlich
UINavigationController tutorial Techotopia

UITableView datasource methods not called on reloadData in IOS

I am stucked in this problem for many hours and have n't found any solution on SO...
I have got a table as a subview in UIViewController. When view loads, all datasource methods are called for tableview, but as I receive data from server and call [someTable reloadData], none of the data source methods are called. I have confirmed through breakpoints that my array do contains 100 objects. Also both delegate and datasource are bind to File owner in IB.
What can be possibly missing ? Please help me... Thanks :(
OutLogController.h
#interface OutLogController : UIViewController<UITableViewDataSource,UITableViewDelegate,ASIHTTPRequestDelegate>
{
NSMutableArray *outstandingKeys;
}
#property (strong, nonatomic) IBOutlet UITableView *someTable;
#end
OutLogController.m
#interface OutLogController ()
#end
#implementation OutLogController
#synthesize someTable;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
outstandingKeys = [[NSMutableArray alloc] init];
someTable = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
someTable.rowHeight = 85;
[self retrieveOutstandingLogFromServer];
}
- (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 outstandingKeys.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
LogUnit *unit = [outstandingKeys objectAtIndex:indexPath.row];
cell.textLabel.text = unit.symbol;
return cell;
}
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 85;
}
-(void) requestFinished:(ASIHTTPRequest *)request
{
NSLog(#"%#",request.responseString);
NSArray *list = [request.responseString JSONValue];//contains 100 objects
for (int i = 0; i < list.count; i++) {
NSArray *singleTrade = [[list objectAtIndex:i] JSONValue];
LogUnit *unit = [[LogUnit alloc] init];
unit.symbol = [singleTrade objectAtIndex:0];
unit.type = [singleTrade objectAtIndex:1];
unit.price = [singleTrade objectAtIndex:2];
unit.remaining = [singleTrade objectAtIndex:3];
unit.order = [singleTrade objectAtIndex:4];
unit.time = [singleTrade objectAtIndex:5];
[outstandingKeys addObject:unit];
}
if(outstandingKeys.count > 0)
{
[someTable reloadData];//does reload table
}
}
EDIT
After removing line:
someTable = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
Datasource methods are called except cellForRowAtIndexPath and table disappears from view since this method is not called. Any idea why it can't get called?
Note: I have confirmed that I have count = 100 after response from server.
someTable = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
You have already bind your UITableView from nib/storyboard. In this case you did not have to alloc again the tableview. Removing this line will do the work
someTable = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
You create new tableView and it doesn't add to current view.
check your outstandingKeys Count may it zero count
Try to reload data by performing it on main thread..
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableRating reloadData];
});
This will solve your problem. Happy Coding..

Error with SplitView

I have an iphone app that I'm trying to make a universal app. I created a separate project to play around with creating a split view app for iPad. I got the basics of it working so I'm trying to implement it in my existing project but I'm getting an error when running on iPad.
2013-06-06 08:57:08.716 KFBNewsroom[26898:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "KFBMasterViewController" nib but didn't get a UITableView.'
The code for the split view is the same as it was in my test project so I can't figure out why it won't work here. Any ideas?
Here is the code from my didFinishLaunchingWithOptions method where I say what to load on different devices.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
self.viewController = [[KFBViewController alloc] initWithNibName:#"KFBViewController" bundle:nil];
self.window.rootViewController = self.tabBarController;
}
else
{
masterViewController.detailViewController = detailViewController;
self.splitViewController = [[UISplitViewController alloc] init];
self.splitViewController.delegate = detailViewController;
self.splitViewController.viewControllers = #[masterNavigationController, detailNavigationController];
self.window.rootViewController = self.splitViewController;
}
MasterViewController.h:
#import <UIKit/UIKit.h>
#class KFBDetailViewController;
#interface KFBMasterViewController : UITableViewController
#property (strong, nonatomic) KFBDetailViewController *detailViewController;
#end
MasterViewController.m:
#import "KFBMasterViewController.h"
#import "KFBDetailViewController.h"
#import "DetailViewManager.h"
#interface KFBMasterViewController () {
NSMutableArray *_objects;
NSMutableArray *menu;
}
#end
#implementation KFBMasterViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(#"Master", #"Master");
self.clearsSelectionOnViewWillAppear = NO;
self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0);
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// self.navigationItem.leftBarButtonItem = self.editButtonItem;
// UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(insertNewObject:)];
// self.navigationItem.rightBarButtonItem = addButton;
menu = [NSMutableArray arrayWithObjects:#"Home", #"Public Affairs", #"Action Alerts", #"Market Updates", #"Ag Stories", #"KFB News", #"Member Benefits", #"Monthly Video", #"Photos", #"Social Media", #"About Us", #"Contact Us", #"KYFB.com", nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)insertNewObject:(id)sender
{
if (!_objects) {
_objects = [[NSMutableArray alloc] init];
}
[_objects insertObject:[NSDate date] atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return menu.count;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UIImageView *image = [[UIImageView alloc]init];
image.image = [UIImage imageNamed:#"CellImage.png"];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// NSDate *object = _objects[indexPath.row];
// cell.textLabel.text = [object description];
cell.textLabel.text = [menu objectAtIndex:indexPath.row];
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.textLabel.highlightedTextColor = [UIColor darkGrayColor];
cell.textLabel.font = [UIFont fontWithName:#"FranklinGothicStd-ExtraCond" size:20.0];
cell.textLabel.textColor = [UIColor whiteColor];
cell.backgroundView = image;
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
[_objects removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationFade];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
}
}
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
#end
You probably have to change the super-class of your rootViewController from UITableViewController to UIViewController.

Resources