please help .... i have a tableview with a list of vehicle
what i want is each of those vehicles to push a view with a text/paragraph describing each of those vehicles. I am new to coding so please try to keep your answers simple
this is my table.h
#import <UIKit/UIKit.h>
#interface table_1 : UITableViewController
{
NSMutableArray *vehicle;
}
#end
this is my table.m
#import "table 1.h"
#import "detailview.h"
#implementation table_1
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
vehicle = [[NSMutableArray alloc] init];
[vehicle addObject:#"sedan"];
[vehicle addObject:#"van"];
[vehicle addObject:#"suv"];
[vehicle addObject:#"truck"];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#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 [vehicle 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...
cell.textLabel.text = [vehicle objectAtIndex:indexPath.row];
return cell;
}
- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath {
//return UITableViewCellAccessoryDetailDisclosureButton;
return UITableViewCellAccessoryDisclosureIndicator;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *selectedcar = [vehicle objectAtIndex:indexPath.row];
detailview *dvController = [[detailview alloc] initWithNibName:#"detailview" bundle:[NSBundle mainBundle]];
dvController.selectedVehicle = selectedcar;
[self.navigationController pushViewController:dvController animated:YES];
dvController = nil;
}
#end
this is detailview.h
#import <UIKit/UIKit.h>
#interface detailview : UIViewController
{
IBOutlet UILabel *lblText;
NSString *selectedVehicle;
}
#property (nonatomic, retain) NSString *selectedVehicle;
#end
this is detail.m
#import "detailview.h"
#implementation detailview
#synthesize selectedVehicle;
Xcode 4.2 has a Master-Detail Application project template which provides a starting point for the master-detail application you're trying to implement.
Related
I'm new to iOS developing, I have a UITableViewController and I want to load NSMutableArray data in the table, but it does load data and shows an empty table. It's the code:
#import "PhotosTableViewController.h"
#implementation PhotosTableViewController
NSMutableArray *photos;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
photos = [[NSMutableArray alloc] init];
Photo *pic = [[Photo alloc] init];
[pic setName:#"over look"];
[pic setFilename:#"overlook.png"];
[pic setNotes:#"this is notw!"];
[photos addObject:pic];
pic = [[Photo alloc] init];
[pic setName:#"olives"];
[pic setFilename:#"olives.png"];
[pic setNotes:#"this is notw!"];
[photos addObject:pic];
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#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 [photos count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"PhotoCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
Photo *current=[photos objectAtIndex:indexPath.row];
cell.textLabel.text=[current name];
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
}
#end
Add [self.view reloadData]; at the end of your viewDidLoad implementation.
If that does not help already, I suspect that your viewController is actually not of type PhotoTableViewController. Make sure that is correctly setup. If done via InterfaceBuilder, check the type of the viewController and make sure it says PhotoTableViewController.
Le Sigh you'd be surprised how many UITableView questions are solved with 'Make your class the delegate and datasource.'. In IB, drag the outlets to files owner. In code, set tableView.delegate = self; and tableView.datasource = self;
Having trouble implementing the following to look like this:
Design view: http://i53.tinypic.com/2hqe9lk.png
Simulator view: http://i56.tinypic.com/2luw68j.png
It doesn't display the background, textbox, nor the submit button :( All it displays is the table.
What am I doing wrong?
Thanks!!!
Code for the view is as follows;
BooksTableViewController.m
//
// BooksTableViewController.m
// ORBooks
//
// Created by Elisabeth Robson on 6/19/09.
// Copyright 2009 Elisabeth Robson. All rights reserved.
//
#import "BooksTableViewController.h"
#import "BookDetailViewController.h"
#import "ORBooksAppDelegate.h"
#implementation BooksTableViewController
#synthesize booksArray;
#synthesize bookDetailViewController;
#synthesize number;
/*
- (id)initWithStyle:(UITableViewStyle)style {
// Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
if (self = [super initWithStyle:style]) {
}
return self;
}
*/
- (void)viewDidLoad {
[super viewDidLoad];
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle: #"Back" style: UIBarButtonItemStyleBordered target: nil action: nil];
[[self navigationItem] setBackBarButtonItem: newBackButton];
[newBackButton release];
NSMutableArray *array = [[NSArray alloc] initWithObjects:#"sub1", #"sub2", nil];
self.booksArray = array;
[array release];
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
/*
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
*/
/*
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
/*
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
}
*/
/*
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}
#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 2;//[self.booksArray 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] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
NSUInteger row = [indexPath row];
cell.text = [booksArray objectAtIndex:row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.
// AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:#"AnotherView" bundle:nil];
// [self.navigationController pushViewController:anotherViewController];
// [anotherViewController release];
NSInteger row = [indexPath row];
if (self.bookDetailViewController == nil) {
BookDetailViewController *aBookDetail = [[BookDetailViewController alloc] initWithNibName:#"BookDetailView" bundle:nil];
self.bookDetailViewController = aBookDetail;
[aBookDetail release];
}
//bookDetailViewController.title = [NSString stringWithFormat:#"%#", [booksArray objectAtIndex:row]];
//ORBooksAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
//[delegate.booksNavController pushViewController:bookDetailViewController animated:YES];
[self.navigationController pushViewController:bookDetailViewController animated:YES];
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
}
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)dealloc {
[bookDetailViewController release];
[super dealloc];
}
#end
BooksTableViewController.h
//
// BooksTableViewController.h
// ORBooks
//
// Created by Elisabeth Robson on 6/19/09.
// Copyright 2009 Elisabeth Robson. All rights reserved.
//
#import <UIKit/UIKit.h>
#class BookDetailViewController;
// don't need to specify the delegate, datasource interfaces; UITableViewController gets those automatically
#interface BooksTableViewController : UITableViewController {
IBOutlet UITextField *number;
IBOutlet UITableView *booksTableView;
NSMutableArray *booksArray;
BookDetailViewController *bookDetailViewController;
}
- (IBAction)submit:(id)sender;
#property (nonatomic, retain) UITextField *number;
#property (nonatomic, retain) NSMutableArray *booksArray;
#property (nonatomic, retain) BookDetailViewController *bookDetailViewController;
#end
You'll have to change the UITableViewController to UIViewController in the header file.
What you are doing is adding everything to the tableview. Instead you'll have to add your tableview to the UIViewController and the same for UITextfield and UIButton.
Rest is fine.
I created UI for Iphone that has a button and label above tableview. The problem is that data doesn't show in table despite setting it in cellForRowAtIndexPath method.
I get this:
This is my code for controller of third tab. Header:
#import <UIKit/UIKit.h>
#interface ThirdView : UIViewController <UITableViewDelegate,UITableViewDataSource> {
//model
NSMutableArray *podatki;
//view
UITableView *myTableView;
}
#property(nonatomic,retain) NSMutableArray *podatki;
#property(nonatomic,retain) UITableView *myTableView;
-(IBAction)pritisnuGumb:(UIButton *) sender; //
#end
Implementation:
#import "ThirdView.h"
#implementation ThirdView
#synthesize podatki;
#synthesize myTableView;
-(void)viewDidLoad{
myTableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain];
myTableView.delegate = self;
myTableView.dataSource = self;
myTableView.autoresizesSubviews = YES;
podatki = [[NSMutableArray alloc] init];
[podatki addObject:#"Sunday"];
[podatki addObject:#"MonDay"];
[podatki addObject:#"TuesDay"];
[super viewDidLoad];
//self.view = myTableView;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [podatki count];
}
-(IBAction)pritisnuGumb:(UIButton *) sender {
NSLog(#"buca");
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.numberOfLines = 4;
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
NSString *naslov = [podatki objectAtIndex:indexPath.row];
cell.textLabel.text = naslov;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(#"kliknu na vrstico");
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)dealloc {
[podatki release];
[super dealloc];
}
#end
If i uncomment line "self.view = myTableView;" i get tableview with data but label and button above it disappear (tableview is fullscreen).
What am i doing wrong here?
#Jennis:
I tried your solution and data inside table is now visible but upper part is squeezed like this:
I believe that you can do like
[self.view addSubview:myTableView];
[self.view sendSubviewToBack:myTableView].
hope it helps
I have successfully loaded the muscleName items into a table view but am not having any luck loading their respective exerciseName into the 2nd table view.
The method I am using is:
cell.textLabel.text = [[self.exerciseArray objectAtIndex:indexPath.row] objectForKey: #"exerciseName"];
Maybe I need to define constants?
Edit:
Here is the code in ViewDidLoad for the first table that loads muscleName:
if (muscleArray == nil)
{
//Read the plist file into an array (the root element is an array)
NSString *path = [[NSBundle mainBundle]pathForResource:#"test" ofType:#"plist"];
NSMutableArray *rootLevel = [[NSMutableArray alloc]initWithContentsOfFile:path];
self.muscleArray = rootLevel;
[rootLevel release];
Here is my current sub table class
import "SpecificExerciseTableViewController.h"
#import "MusclesTableViewController.h"
#import "CurlAppDelegate.h"
#import "DetailViewController.h"
#implementation SpecificExerciseTableViewController
#synthesize exerciseArray;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
}
return self;
}
- (void)dealloc
{
[exerciseArray release];
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
self.navigationItem.title = #"Exercises";
[super viewDidLoad];
if (exerciseArray == nil)
{
//Read the plist file into an array (the root element is an array)
NSString *path = [[NSBundle mainBundle]pathForResource:#"test" ofType:#"plist"];
NSMutableArray *rootLevel = [[NSMutableArray alloc]initWithContentsOfFile:path];
self.exerciseArray = rootLevel;
[rootLevel release];
}
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.exerciseArray 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] autorelease];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [[self.exerciseArray objectAtIndex:indexPath.row]objectForKey:#"exerciseName"];
return cell;
}
- (UITableViewCellAccessoryType)tableView:(UITableView *)tv accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellAccessoryDisclosureIndicator;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
#end
Without seeing more of your code, it looks like you're accessing the exerciseName property okay if you are starting at exercises.
Are you sure that self.exerciseArray is pointing to your exercises object? The quickest way to check is just drop in an NSLog() statement and see if you have what you think you have:
NSLog(#"Exercises: %#", self.exerciseArray);
Alright this is what I have so far in my application, the main view which has a tableview with different tasks. When you touch one it pushes to the DetailViewController. I have been trying to make an internal tableview in the detailview. So I have a TableController up now but now when I click a task it just freezes.
Update Added Code:
//RootViewController
#import "RootViewController.h"
#import "DetailViewController.h"
#implementation RootViewController
#synthesize toolbar;
#synthesize window;
#pragma mark -
#pragma mark View lifecycle
- (void)viewDidLoad {
theArray = [[NSArray alloc] initWithObjects:#"Kill Taylor",#"Stab Taylor",#"Pay Jordan",nil];
//theArray = [[NSMutableArray alloc] init];
[super viewDidLoad];
addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(addButtonPressed)];
self.navigationItem.rightBarButtonItem = addButton;
self.navigationItem.leftBarButtonItem = self.editButtonItem;
//self.navigationItem.rightBarButtonItem = addButton;
// self.navigationItem.rightBarButtonItem = addButton;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath {
//return UITableViewCellAccessoryDetailDisclosureButton;
return UITableViewCellAccessoryDetailDisclosureButton;
}
-(void) addButtonPressed
{
NSString *selectedAction = #"add";
DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:#"DetailView" bundle:[NSBundle mainBundle]];
dvController.selectedAction = selectedAction;
//dvController.selectedTask = selectedTask;
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];
dvController = nil;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
/*
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
*/
/*
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
}
*/
/*
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [theArray 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] autorelease];
}
cell.textLabel.text = [theArray objectAtIndex:indexPath.row];
return cell;
}
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
if (editing)
{
// turn on the "add" button when editing
//self.navigationItem.rightBarButtonItem = addButton;
}
else
{
// remove the "add" butto when not editing
//self.navigationItem.rightBarButtonItem = nil;
}
[super setEditing:editing animated:animated];
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source.
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject: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;
}
*/
#pragma mark -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *selectedAction = #"details";
NSString *selectedTask = [theArray objectAtIndex:indexPath.row];
DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:#"DetailView" bundle:[NSBundle mainBundle]];
dvController.selectedAction = selectedAction;
dvController.selectedTask = selectedTask;
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];
dvController = nil;
}
#pragma mark -
#pragma mark Memory management
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Relinquish ownership any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
// For example: self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
#end
The above all works
#import "DetailViewController.h"
#implementation DetailViewController
#synthesize selectedTask;
#synthesize selectedAction;
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization.
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
if(selectedAction == #"details"){
[super viewDidLoad];
self.navigationItem.title = #"Task Details";
//lblText.text = selectedTask;
}
else if(selectedAction == #"add"){
[super viewDidLoad];
self.navigationItem.title = #"Add Task";
//lblText.text = selectedTask;
}
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc. that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[selectedTask release];
[lblText release];
[super dealloc];
}
#end
This does not work if it has any stuff that build the inside table.
I think the problem may be in your viewDidLoad method in DetailedViewController. Fix the following two things and see if that makes a difference.
Move your [super viewDidLoad] so out of your if conditional.
Compare string in the right ways using the isEqualToString: method
Here's your code, tweaked:
- (void)viewDidLoad
{
[super viewDidLoad];
if(selectedAction isEqualToString: #"details")
{
self.navigationItem.title = #"Task Details";
//lblText.text = selectedTask;
}
else if (selectedAction isEqualToString: #"add")
{
self.navigationItem.title = #"Add Task";
//lblText.text = selectedTask;
}
}