A
A
anonymous222013-11-22 12:56:14
Objective-C
anonymous22, 2013-11-22 12:56:14

Passing data View Controller - View, strange behavior?

I have a View Controller ( PagedFlowView ) which contains a custom view ( Collapse click ).
Essentially, my View Controller has a method

- (UIView *)flowView:(PagedFlowView *)flowView cellForPageAtIndex:(NSInteger)index;

Which is very similar in its properties to the Table View method
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

In the code below I use this method in my View Controller(pagedFlowView) to create a custom view(Collapse click) and pass the page index property someData
- (UIView *)flowView:(PagedFlowView *)flowView cellForPageAtIndex:(NSInteger)index{
        
        mainDetailV = (MainDetailView *)[flowView dequeueReusableCell];
        
        if (!mainDetailV) {//creating pages flow one by one
            mainDetailV = [[[NSBundle mainBundle] loadNibNamed:@"MainDetailView"  owner:self    options:nil] lastObject];
            mainDetailV.layer.masksToBounds = YES;
        }
        mainDetailV.shouldDraw = YES;
        mainDetailV.someData = [NSString stringWithFormat:@"%i",index];//transfer index to custom view
        return mainDetailV;
    }

This code creates n pages with a view that has some property. I am passing the index of the page to this property(mainDetailV.someData) in order to use the index.
In my custom view(Collapse click) I initialize my view in the - (void)drawRect:(CGRect)rect; , yes, I understand that this is not very good for performance, but at this stage I'm not interested in it.
I initialize the view in the code below:
- (void)drawRect:(CGRect)rect{
        [self initMehod];
    }
    
    -(void) initMehod{
     
        myCollapseClick.CollapseClickDelegate = self;
    
        myCollapseClick.alpha = 0.8;    
        [myCollapseClick reloadCollapseClick];
    }

As you can see from the documentation, I use the method
-(NSString *)titleForCollapseClickAtIndex:(int)index
;, in order to set the page index (used earlier):
-(NSString *)titleForCollapseClickAtIndex:(int)index {
        return someData;
    }

As you can see from the code, everything is quite simple. But my problem is this: when I pass in an index and my views are displayed, I see the following indexes in their title: 1 2 3 8 4 7 5 6, but not indexes from 1 to 8 (ascending).
I understand that this is a very specific question. But maybe someone has an idea what I'm doing wrong?
***EDIT:***
When I try to console the index in the following method
- (UIView *)flowView:(PagedFlowView *)flowView cellForPageAtIndex:(NSInteger)index{
         
            mainDetailV = (MainDetailView *)[flowView dequeueReusableCell];
            
            if (!mainDetailV) {//creating pages flow one by one
                mainDetailV = [[[NSBundle mainBundle] loadNibNamed:@"MainDetailView"  owner:self    options:nil] lastObject];
                mainDetailV.layer.masksToBounds = YES;
            }
            
            mainDetailV.shouldDraw = YES;
            mainDetailV.someData = [NSString stringWithFormat:@"%i",index];//transfer index to custom view
            NSLog(@"%li",index); // HERE
            
            return mainDetailV;
        }

The result in the console is very strange:
1
2
3
4
5
6
7
1
2
3
4
5
6
7
and after scrolling to the next View
3
4
5
6
7
and so on.
Thank you!
Question on StackOverflow

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
A
An, 2013-11-26
@anonymous22

When I try to console the index in the following method

Well, let's play telepaths. My move.
A quick look at the PagedFlowView code makes you horrified, since this custom table is reloaded in layoutSubviews by some _needsReload flag, which is private (1), is set to YES (2) when the application is initialized and ... is never reset again (3). Thus, every time setNeedsLayout is sent to this PagedFlowView , it reloads the data from the source data. And setNeedsLayout is called probably often....
As for the first one, God knows. half of the code is missing, it's even hard to guess
Well, it's actually something thermonuclear
- (void)drawRect:(CGRect)rect{
[self initMehod];
}

N
Ne0nX, 2013-11-25
@Ne0nX

Could you upload a test project?
Perhaps the problem is in the PagedFlowView.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question