开发者

getting problem for updating my tableview value to detail lable section

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 = (FertilityAppAppDeleg开发者_如何学Cate
    *)[[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 assigning lable to symptomlabel. In this case, the symptomlabel may not retain the string lable. You try having Updatetableviewlable: method like this.

- (void)Updatetableviewlable:(NSString*)lable {

    symptomlabel = [lable retain];
    NSLog(@"%@", symptomlabel);
}

And make sure your cellForRowAtIndexPath: method looks something like this.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    ...

    UILabel *myLabel;

    if (cell == nil) {

        myLabel = [[UILabel alloc] initWithFrame:CGRectMake(160, 25, 125, 15)];
        myLabel.backgroundColor = [UIColor clearColor];
        myLabel.textColor=[UIColor blueColor];
        myLabel.text = symptomlabel;
        [myLabel setTag:1];
        [cell.contentView addSubview:myLabel];
        [myLabel release];

    } else {

        myLabel = [[cell contentView] viewWithTag:1];
        myLabel.text = symptomlabel;
    }

    ...
}

Add also make sure you are reloading the table view in viewWillAppear: method of your First.m.

- (void)viewWillAppear:(BOOL)animated { 

    [[self tableView] reloadData]; 
}


Do an reload data on your table view. This will call again your cellForRowAtIndexPath.

In your setter add [self.tableView reloadData];

Edit:

1 . You have to release your label.

2 . Other problem you can add many labels to your cells when you are reusing it. Dest you subclass UITableViewCell and do your custom layout there. This will improve scroll performance on slow devices like iPhone 3G. Try in your cellForRowAtIndexPath not to alloc and init objects and not to do computing code (for(), while()). This will improve your scroll performance very much.

Edit 2:

You must set on your property (copy) or (retain) @property (nonatomic,retain) NSString *symptomlabel;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜