My application is navigation base , I have two Table ViewControllers ,I am selecting data from second tableview and updating to details label of first tabaleview. The following code i am tried but not updating , I am getting secondtableview value in “Updatetableviewlable” method but i am not updating “cellForRowAtIndexPath” method, where i am doing mistake .. please any one guide me .
@class First;
@interface FertilityAppAppDelegate
First *firstObj;
@property (nonatomic,retain) First *firstObj;
@implementation FertilityAppAppDelegate
@synthesize firstObj;
> didFinishLaunchingWithOptions
//code 1
// Updating detail view from second tableview to first tableview .
firstObj= [[First alloc] initWithNibName: @"First" bundle:nil];
UINavigationController *aNavigationController = [[UINavigationController alloc] initWithRootViewController: firstObj];
self.navigationController = aNavigationController;
[window addSubview:navigationController.view];
[window makeKeyAndVisible];
return YES;
//code 2
// Not Updating detail view from second tableview to first tableview
mainmenuObj = [[Mainmenu alloc] initWithNibName:@"Mainmenu" bundle:nil];
firstObj= [[First alloc] initWithNibName: @"First" bundle:nil];
UINavigationController *aNavigationController = [[UINavigationController alloc] initWithRootViewController: mainmenuObj];
self.navigationController = aNavigationController;
[window addSubview:navigationController.view];
[window makeKeyAndVisible];
return YES;
@interface First
NSString *symptomlabel; FertilityAppAppDelegate *Appdelegate;
@property (nonatomic,retain) NSString *symptomlabel
@implementation First
@synthesize symptomlabel;
- (void)viewDidLoad
{
Appdelegate = (FertilityAppAppDelegate*)[[UIApplication sharedApplication] delegate];
}
-(void) Updatetableviewlable:(NSString*)lable
{
symptomlabel=[lable retain] ;
NSLog(@"the update value is %@", lable);
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath
{
static NSString *cellId = @"CellId";
UITableViewCell *cell = (UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:cellId];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellId] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
switch (indexPath.section)
{
case 0:
{
cell.textLabel.text = [self.MenstruationtoWakingArray objectAtIndex:indexPath.row];
if(indexPath.row==0)
{
UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(160, 25, 125, 15)];
myLabel.text =symptomlabel;
myLabel.backgroundColor = [UIColor clearColor];
myLabel.textColor=[UIColor blueColor];
[self.tableView addSubview:myLabel];
NSLog(@"The Save file is:%@",symptomlabel);
}
//statement case upto 10
}
}
}
@interface Second : UITableViewController
{
FertilityAppAppDelegate *appDelegate;
}
@implementation Second tableview
viewDidLoad
appDelegate = (FertilityAppAppDelegate
*)[[UIApplication sharedApplication] delegate];
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
*)indexPath
{
if(indexPath.section==0)
{
if (indexPath.row==0)
{
NSString *updatelable =@"None";
[appDelegate.firstObj Updatetableviewlable:updatelable];
appDelegate.selectedRow =indexPath.row;
}
//statement upto row 5
}
[self.tableView reloadData];
}
In your
Updatetableviewlable:method, you are assigninglabletosymptomlabel. In this case, thesymptomlabelmay not retain the stringlable. You try havingUpdatetableviewlable:method like this.And make sure your
cellForRowAtIndexPath:method looks something like this.Add also make sure you are reloading the table view in
viewWillAppear:method of yourFirst.m.