Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
Problem with adding data to a singleton mutablearray
Hi, i have a problem that i can't figure out. With some help from some nice guys in here i figured out how to use a singleton class. In the singleton class i have a mutablearray. The arra is shared to a class which have a tableview. There is a barbuttonitem which push you to a modal controller and when you hit save in that view a new object should be added to the array and tableview.
My class with the tableview looks like this:
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib.
Don't worry i know that compiling a empty method won't do anything, its because i downloaded a file, that did it for me so i should just call sharedMyClassName and then the file does it for me. But now i created my own singleton class, and it still won't work :(
when i click save nothing happens its just a plain tableview, its like the cellForRow doesnt work together with a singleton array because if i create a normal array everything works fine. What should i do? :)
First you are going to leak your property. It won't matter because it's a singleton but still. First, if you are going to alloc a property do it with this 3 step pattern:
Replies
New app - See screenshots and details at www.globaclock.com.
If you want to
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomearrayForSaved = [[NSMutableArray alloc] init];
}
but then it says that its a non-void function. What should i do? i tried to return 0 but then it crashes when i run the save function :(
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome-(id)init {
self =[super init];
If (self = super init) {
arraysForSaved = [[NSMutableArray alloc]init];
}
return self;
}
In my save function i do:
[[DataHandlerSingleto sharedDataHandlerSingleton].arrayForSaved addObject:@"Test"];
And then i dismiss the view. In my tableview class i make the singleton array count and cellForRow i use this to set the different rows:
cell.textLabel.text = [[DataHandlerSingleto sharedDataHandlerSingleton].arrayForSaved objectAtIndex:indexPath.row];
I can't figure out what im doing wrong :(
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeNew app - See screenshots and details at www.globaclock.com.
If you want to
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome+(DataHandlerSingleto *)sharedDataHandlerSingleton;
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeNew app - See screenshots and details at www.globaclock.com.
If you want to
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeHere is a tutorial on creating a Singleton: The Objective-C Singleton
New app - See screenshots and details at www.globaclock.com.
If you want to
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeSingletonData.h
SingletonData.m
Then i create a private in the delegate:
@private SingletonData *sharedData;
Launching with options i call:
sharedData = [SingletonData sharedDataInstance];
That should work fine. The annoying part comes when i create a object and put it into my array.
SavedCalculationsTableView.m
then it pushes the modal controller AddInterface.m
when i click save nothing happens its just a plain tableview, its like the cellForRow doesnt work together with a singleton array because if i create a normal array everything works fine. What should i do? :)
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeAnd then you have to release it in your dealloc method:
Try calling reloadData on your table view.
New app - See screenshots and details at www.globaclock.com.
If you want to
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome