Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kurushetra

macrumors newbie
Original poster
Mar 19, 2009
11
0
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 ];

} 


}
 

themoonisdown09

macrumors 601
Nov 19, 2007
4,319
18
Georgia, USA
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 ];
     }

}
 

kurushetra

macrumors newbie
Original poster
Mar 19, 2009
11
0
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...
 

themoonisdown09

macrumors 601
Nov 19, 2007
4,319
18
Georgia, USA
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...

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.
 

eddietr

macrumors 6502a
Oct 29, 2006
807
0
Virginia
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...

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.
 

kurushetra

macrumors newbie
Original poster
Mar 19, 2009
11
0
awakefromnib

-(void)setnamelist
{ 

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 ];

} 


}

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

-(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 ];

} 


}
 

Saladinos

macrumors 68000
Feb 26, 2008
1,845
4
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)?
 

kurushetra

macrumors newbie
Original poster
Mar 19, 2009
11
0
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.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
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]
 

eddietr

macrumors 6502a
Oct 29, 2006
807
0
Virginia
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.

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?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.