Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 7, 2009, 07:33 AM   #1
kurushetra
macrumors newbie
 
Join Date: Mar 2009
Awakefromnib problem

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

} 


}
kurushetra is offline   0 Reply With Quote
Old Apr 7, 2009, 07:37 AM   #2
themoonisdown09
macrumors 601
 
themoonisdown09's Avatar
 
Join Date: Nov 2007
Location: 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 ];
     }

}
themoonisdown09 is offline   0 Reply With Quote
Old Apr 7, 2009, 08:37 AM   #3
kurushetra
Thread Starter
macrumors newbie
 
Join Date: Mar 2009
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...
kurushetra is offline   0 Reply With Quote
Old Apr 7, 2009, 08:40 AM   #4
themoonisdown09
macrumors 601
 
themoonisdown09's Avatar
 
Join Date: Nov 2007
Location: Georgia, USA
Quote:
Originally Posted by kurushetra View Post
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.
themoonisdown09 is offline   0 Reply With Quote
Old Apr 7, 2009, 11:43 AM   #5
eddietr
macrumors 6502a
 
Join Date: Oct 2006
Location: Virginia
Quote:
Originally Posted by kurushetra View Post
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.
eddietr is offline   0 Reply With Quote
Old Apr 7, 2009, 12:46 PM   #6
kurushetra
Thread Starter
macrumors newbie
 
Join Date: Mar 2009
awakefromnib

Quote:
-(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:

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

} 


}
kurushetra is offline   0 Reply With Quote
Old Apr 7, 2009, 12:58 PM   #7
Saladinos
macrumors 68000
 
Saladinos's Avatar
 
Join Date: Feb 2008
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)?
Saladinos is offline   0 Reply With Quote
Old Apr 7, 2009, 01:14 PM   #8
kurushetra
Thread Starter
macrumors newbie
 
Join Date: Mar 2009
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.
kurushetra is offline   0 Reply With Quote
Old Apr 7, 2009, 01:34 PM   #9
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
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:
- (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];
}

Last edited by kainjow; Apr 7, 2009 at 01:56 PM.
kainjow is offline   0 Reply With Quote
Old Apr 7, 2009, 04:57 PM   #10
eddietr
macrumors 6502a
 
Join Date: Oct 2006
Location: Virginia
Quote:
Originally Posted by kurushetra View Post
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?
eddietr is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
GoodPlayer Problem - Never mind. Problem solved. BasicGreatGuy iPad Apps 0 Mar 14, 2014 01:18 PM
iTunes DRM problem? Or, HD Versions of Movie on ATV1 Problem? Aqueous Apple TV and Home Theater 5 Feb 9, 2014 07:54 AM
iPhone: Gmail App problem or Jailbreak Problem? ARSkemp Jailbreaks and iOS Hacks 6 Apr 9, 2013 11:43 PM
Help, unexplainable problem (for me) [Intermittent slowdown problem] LittleBig MacBook Pro 5 Nov 5, 2012 05:29 PM

Forum Jump

All times are GMT -5. The time now is 08:01 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC