Awakefromnib problem

Discussion in 'Mac Programming' started by kurushetra, Apr 7, 2009.

  1. macrumors newbie

    Joined:
    Mar 19, 2009
    #1
    hello, i have a method and only is working if is call in awakefromnib but if i want to change the name of the method and call it when i want then is not working ¿somebody can tell me why?, and how to run this method no in awakefromnib.

    The application is one tableview and there is set the sentence "Entity number", there are two bindings, one for an Array controller
    to the appcontroller set to "list",and another in the table column, bind to the Array controller, well how i say this works but only from awakefromnib...





    -(void) awakeFromNib
    { 

    list = [ [ NSMutableArray alloc ] init ];
    int i; 

    NSMutableArray *actualData;
    

 for( i =0; i< 4; i++ )
    { 

    DNBindingEntity *ent = [ [ DNBindingEntity alloc ] init ];
    
[ ent setName: [ NSString stringWithFormat: @"Entity number %i", i ] ]; 

    
actualData = [ self list ];
    
[ actualData insertObject: ent atIndex: i ];
    [ self setList: actualData ]; 

    
[ ent release ];
    
} 

    
}
     
  2. macrumors 601

    themoonisdown09

    Joined:
    Nov 19, 2007
    Location:
    Georgia, USA
    #2
    Why don't you just put the contents into a separate function.

    Code:
    - (void)awakeFromNib
    {
        [self myFunction];
    }
    
    - (void)myFunction
    { 
         list = [ [ NSMutableArray alloc ] init ]; 
         int i; 

         NSMutableArray *actualData;
    
         for( i =0; i< 4; i++ )
         { 
              DNBindingEntity *ent = [ [ DNBindingEntity alloc ] init ];
              [ent setName: [ NSString stringWithFormat: @"Entity number %i", i ] ];
              actualData = [ self list ];
              [ actualData insertObject: ent atIndex: i ];
              [ self setList: actualData ];
              [ ent release ];
         }

    }
    
     
  3. thread starter macrumors newbie

    Joined:
    Mar 19, 2009
    #3
    awakefromnib

    but what i want is not run the method in the begining of the app i like to run it
    only when i press a button ,and then is not working , i also try to run the awakefromnib in the acction of the button but not work...
     
  4. macrumors 601

    themoonisdown09

    Joined:
    Nov 19, 2007
    Location:
    Georgia, USA
    #4
    I don't think you're supposed to call awakeFromNib. This gets called once everything has been initialized. Check all your init methods to make sure that there are no errors... this might be why it's not getting called.
     
  5. macrumors 6502a

    Joined:
    Oct 29, 2006
    Location:
    Virginia
    #5
    Can you post the version that is not working? That would make it easier to figure out what's wrong.

    Also, can you post your code in tags, please, so it's easier to read.
     
  6. thread starter macrumors newbie

    Joined:
    Mar 19, 2009
    #6
    awakefromnib

    this code is not working, but is working if i call it from awaefromnib:

     
  7. macrumors 68000

    Saladinos

    Joined:
    Feb 26, 2008
    #7
    Your English makes it difficult to understand what exactly the problem is.

    I think what you're saying is that the code only works in awakeFromNib. If you put it in another function and make it the target of a button's click action, for example, it doesn't work.

    How exactly does it not work? Does it compile? Does it raise an exception? Or does it run but not give you the desired effect (test with an NSLog statement inside the function)?
     
  8. thread starter macrumors newbie

    Joined:
    Mar 19, 2009
    #8
    awakefromnib

    Sorry for my english , well is what you say.
    the code is runing and if i put a nslog is runing , and i dont get any error,
    but the tableview is empty.
    The strange is what if is runing from the funcion awakefromnib then works good.
     
  9. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #9
    Beyond the several redundancy issues with that code, the only problem I see is the setList: method. What does that look like?

    Edit: I'd change your code to be like this, which should work:

    Code:
    [plain]- (void)setList:(NSArray *)newList
    {
    	if (list != newList)
    	{
    		[list release];
    		list = [newList retain];
    	}
    }
    
    - (void)setnamelist
    {
    	NSMutableArray *tempList = [NSMutableArray array];
    	int i;
    	for (i=0; i<4; i++)
    	{
    		DNBindingEntity *ent = [[[DNBindingEntity alloc] init] autorelease];
    		[ent setName:[NSString stringWithFormat:@"Entity number %i", i]];
    		[tempList addObject:ent];
    	}
    	[self setList:tempList];
    }[/plain]
     
  10. macrumors 6502a

    Joined:
    Oct 29, 2006
    Location:
    Virginia
    #10
    actually I meant code tags, not quote tags. Sorry I wasn't clear. This is so the indentation is preserved and it is quicker to read.

    So kainjow has shown you a cleaner version of the code to create your list. The next question is how is your tableview wired? Are youu
    using bindings?
     

Share This Page