Question

I've made a Folder in my application via JWFolders. My problem is that I've set up some code to get some strings from parse.com and if there's no connection it diplays some text in a CLTickerview. However, if I open the folder a few times the text duplicates every time I open the folder. Here some Images:

After opening first time: enter image description here

After about 5 times: enter image description here

After 10 times: enter image description here

My code:

PFQuery *query = [PFQuery queryWithClassName:@"TestObject"];
[query getObjectInBackgroundWithId:@"object1"
                             block:^(PFObject *textu, NSError *error) {
                                 if (!error) {
                                     // start the tickerview
                                    CLTickerView *ticker = [[CLTickerView alloc] initWithFrame:CGRectMake(0, 35, 320, 35)];
                                    ticker.marqueeStr = [textu objectForKey:@"text"];
                                     ticker.marqueeFont = [UIFont systemFontOfSize:26];


                                     [self.view addSubview:ticker];

                                    // if there's connection

                                 } else {
                                     // Log details of our failure
                                     CLTickerView *ticker = [[CLTickerView alloc] initWithFrame:CGRectMake(0, 35, 320, 35)];
                                     ticker.marqueeStr = @"Keine Internet Verbindung";
                                     ticker.marqueeFont = [UIFont systemFontOfSize:26];

                                     [self.view addSubview:ticker];

                                     //if there's no connection;

                                 }

                             }];

Is there a way to delete the stuff inside the tickerview, after the folder is closed or something like that?

Does have anyone suggestios or solutions for me?

Thanks.

Was it helpful?

Solution

Each and every time you open the folder, you are creating separate instances of CLTickerView *ticker and adding to the view as subview using this line [self.view addSubview:ticker];. If you want to add that only once, you need to create the ticker in a place where you wont call the alloc method repeatedly.

Create in viewDidLoad or so,

CLTickerView *ticker = [[CLTickerView alloc] initWithFrame:CGRectMake(0, 35, 320, 35)];

Then use it as,

PFQuery *query = [PFQuery queryWithClassName:@"TestObject"];
[query getObjectInBackgroundWithId:@"object1"
                             block:^(PFObject *textu, NSError *error) {
                                 if (!error) {
                                     // start the tickerview

                                     ticker.marqueeStr = [textu objectForKey:@"text"];
                                     ticker.marqueeFont = [UIFont systemFontOfSize:26];
                                     [self.view addSubview:ticker];

                                    // if there's connection

                                 } else {
                                     // Log details of our failure
                                     ticker.marqueeStr = @"Keine Internet Verbindung";
                                     ticker.marqueeFont = [UIFont systemFontOfSize:26];

                                     [self.view addSubview:ticker];

                                     //if there's no connection;

                                 }

                             }];

Remember that whenever you call CLTickerView *ticker = [[CLTickerView alloc] initWithFrame:CGRectMake(0, 35, 320, 35)];, it creates separate copies and you cant access the previous one, once the new one is created.

Whenever you want to remove it just use [ticker removeFromSuperview];

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top