Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

tranvutuan

macrumors member
Original poster
Dec 19, 2011
74
0
Iam working on GMGridView and do some customization. Given :
1. I have a gridView containing gridViewCell
2. I have button called checkBox
My Goal is to add checkBox for every gridViewCell
Below what I have so far
Code:
- (GMGridViewCell *)GMGridView: (GMGridView *)gridView cellForItemAtIndex: (NSInteger)index
{  
    CGSize size = [self sizeForItemsInGMGridView:gridView];
    
    GMGridViewCell *cell = [gridView dequeueReusableCell];
    
    if (!cell) 
    {
        cell = [[GMGridViewCell alloc] init];
        // create an UIView
        UIView      *view       =   [[UIView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
 
        // do some customization for my view
        view.backgroundColor = [UIColor purpleColor];
        view.layer.masksToBounds = NO;
        view.layer.cornerRadius = 8;
        view.layer.shadowColor = [UIColor grayColor].CGColor;
        view.layer.shadowOffset = CGSizeMake(5, 5);
        view.layer.shadowPath = [UIBezierPath bezierPathWithRect:view.bounds].CGPath;
        view.layer.shadowRadius = 8;

        // create a button called checkBox
        UIButton    *checkBox   =   [[UIButton alloc] initWithFrame:CGRectMake(70, 20, 150, 25)];
        [checkBox   setTitleColor:[UIColor purpleColor] forState:UIControlStateNormal];
        [checkBox   setImage:[UIImage imageNamed:@"checkbox_not_ticked"] forState: (UIControlStateNormal)];
            // add checkbox to my view
[B]        [view addSubView: checkBox]  [/B]
        cell.contentView = view;

    }

after running it, no checkbox is shown on each cell. I cant see the bug.. Please help if you were experiencing before
I did attach an picture so you can take a look about it
( Again : my goal is to display checkbox on each purple cell)
 

Attachments

  • Screen shot 2011-12-19 at 10.28.08 AM.png
    Screen shot 2011-12-19 at 10.28.08 AM.png
    12.1 KB · Views: 124
Last edited by a moderator:

tranvutuan

macrumors member
Original poster
Dec 19, 2011
74
0
Well, it looks like you've already highlighted the line that is the problem. Objective-C is case sensitive. You should make sure you don't ignore compiler errors, which that line should be giving you one.

Thanks for pointing it out. I have just made a change to
Code:
[view addSubview:checkBox];

It did not work either.. Until I figured it out the problem lies on the line below
Code:
[[cell.contentView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
The line was already there after I added a checkBox to my view
Can you explain because I did not add any subview to my superview which is my cell....
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.