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 7657913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:07:39+00:00 2026-05-31T13:07:39+00:00

Pls help me with this: The AppDelegate has an argument called user: @interface AppDelegate

  • 0

Pls help me with this:

The AppDelegate has an argument called “user”:

@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
    User *user;
}
@property (nonatomic, retain) User *user;

and I init the user instance in the frist viewController:

User *userInfo = [[User alloc] initWithRealName:realName UserId:userId]; 

and set the user to AppDelegate’s:

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.user = userInfo;

In the second viewController, I can get the use’s realName,there is no problem:

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSString *realName = appDelegate.user.realName;

But when I push to another viewController,and I want to get the user’s realName like just now,
but there is an error:EXC_BAD_ACCESS:

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
User *user  = appDelegate.user;
NSLog(@"I am in noticeDetailViewController:%@",user.realName);***//ERROR***

And I want to know why? and how to fix this error.

Thanks!

User.h & User.m

@interface User : NSObject
{
    NSString *realName;
    NSString *userId;
}

@property (nonatomic, retain)NSString *realName;
@property (nonatomic, retain)NSString *userId;
- (id)initWithRealName   :(NSString *)realNameArgument UserId :(NSString *)userIdArgument;
@end

@implementation User
@synthesize realName,userId;

- (id)initWithRealName   :(NSString *)realNameArgument UserId :(NSString *)userIdArgument 

{
    self = [super init];

    if (self)
    {
        realName = realNameArgument;
        userId   = userIdArgument;       
    }
    return self;
}

- (void)dealloc
{
    [super dealloc];
    [realName release];
    [userId release];
}

@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-05-31T13:07:40+00:00Added an answer on May 31, 2026 at 1:07 pm

    AppDelegate does not retain user, so it gets deallocated before you try to access it in:

    NSLog(@"I am in noticeDetailViewController:%@",user.realName);***//ERROR***
    

    So Change AppDelegate by creating a retained property:

    @interface AppDelegate : UIResponder <UIApplicationDelegate> {
    // ...
    @property (retain, nonatomic) User*user;
    // ..
    

    And don’t forget to synthesize it.

    Also change the init method of user to:

    - (id)initWithRealName:(NSString *)realNameArgument UserId:(NSString *)userIdArgument
    {
        self = [super init];
        if (self) {
            self.realName = realNameArgument;
            self.userId   = userIdArgument;       
        }
        return self;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a slider like this example. pls anyone help me.
pls help me. how can I split this String value? my code below wont
can anyone pls help me convert this to vb.net for each (DictionaryEntry<String, Int64> entry
How can i Remove this error. pls Help me in this... Error 1 Cannot
pls help me how to create a .htaccess file as index.php?regional=aaa domain.com/aaa/ list.php?regional=aaa&ctg=bbb&orderby=ccc&page=123 domain.com/list/aaa/bbb/ccc/123/
using Microsoft.SqlServer.Management.SqlStudio.Explorer; unable to find this pls assist [update] found the dll's in this
Pls help me to solve my issue.. In most of my application the Ui
pls help me to understand the conception of UiView and UIViewController, i know that
this is my code <html:select property=singleSelect> <html:option value=0>Select One </html:option> <script type=text/javascript> var nfhEvents
pls use this http://code.google.com/p/google-web-toolkit-doc-1-6/wiki/DevGuideJavaFromJavaScript IFI means int float int but if i want to

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.