PDA

View Full Version : Awakefromnib problem




kurushetra
Apr 7, 2009, 07:33 AM
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
Apr 7, 2009, 07:37 AM
Why don't you just put the contents into a separate function.


- (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
Apr 7, 2009, 08:37 AM
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
Apr 7, 2009, 08:40 AM
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
Apr 7, 2009, 11:43 AM
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
Apr 7, 2009, 12:46 PM
-(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
Apr 7, 2009, 12:58 PM
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
Apr 7, 2009, 01:14 PM
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
Apr 7, 2009, 01:34 PM
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:

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

eddietr
Apr 7, 2009, 04:57 PM
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?