Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7877721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:27:14+00:00 2026-06-03T03:27:14+00:00

i have a navigationcontroller with the root and a second view. the second view

  • 0

i have a navigationcontroller with the root and a second view. the second view contains a pickerview where the user can set the value 0 to 9. i save this value in the nsuserdefaults
and will use it for the numberofrowsinsection in the tableview on the rootviev.
i retrieve the pickervalue form the userdefaults and set it to a NSInteger. NSLog shows me the correct value, but as return value for the table -> no rows. the tableview works, a return value of (for example) 4 shows me 4 rows…

any ideas for me?

here the rootview:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
       return retValv ;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath          *)indexPath
{
UITableViewCell *cell;
cell = [UITableViewCell alloc];
cell = [cell initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
cell.textLabel.text = @"Test";
return cell;
}


-(IBAction)switch1:(id)sender {
 secondView *second=[[secondView alloc]initWithNibName:@"secondView" bundle:nil];


 [self.navigationController pushViewController:second animated:YES];

}

-(IBAction)showLog:(id)sender
{
NSLog(@"retValv is dzt. %i",retValv);

}

- (void)viewDidAppear:(BOOL)animated
{ 
[super viewDidAppear:animated];

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
retValv = [defaults integerForKey:@"myInt"];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.title = @"Locations";
}

- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:       (UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

and the secondview:

#import "secondView.h"


@interface secondView ()

@end

@implementation secondView


-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView
{
return 1;
}

-(NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:     (NSInteger)component
{
return 10;
}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row     forComponent:(NSInteger)component
{
return [NSString stringWithFormat:@"%i",row];
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:    (NSInteger)component
{
NSLog(@"Gewählt: Zeile %i",row);

zeile = row;


NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setInteger:row forKey:@"pickerRow"];
[defaults setInteger:zeile forKey:@"myInt"];
[defaults synchronize];

}

-(IBAction)showInt:(id)sender {

NSLog(@"show value %i",zeile);

  }


- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.

self.title = @"Settings";


NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[picker selectRow:[defaults integerForKey:@"pickerRow"] inComponent:0 animated:NO];
zeile = [defaults integerForKey:@"myInt"];


}

- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:    (UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T03:27:16+00:00Added an answer on June 3, 2026 at 3:27 am

    In the root view move the code to load your number to viewWillAppear instead of viewDidAppear. It is loading the number too late (after the tableview is loaded and displayed).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the navigationcontroller based viewcontroller and I overriding the root view controller navigation
My app's root view controller supports any orientation but user can navigate to another
I have root view that presents navigation controller with content controller, this is how
I know that I can use popToRootViewController if I have navigationController in my project
I have a view inside a tabbarcontroller and navigationcontroller and my 'willAnimateRotationToInterfaceOrientation' method is
I have following code in my application. [self.navigationController pushViewController:x animated:YES]; It will push a
In my app I have a drill-down type interface as follows: My root view,
I have the following set up in a navigation controller. The root is a
I am using navigationcontroller. i have (Root,A,B,C,D) class. i want to sand a string
I have an app which starts with a root UINavigationController . This controller then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.