0

I am pretty new to Xcode and this simple problem has been driving me mad! I have created an expandable table that works fine. This is some of the code on a UIView subclass for the section that expands when you tap on a cell:

- (id)initWithFrame:(CGRect)frame WithTitle: (NSString *) title Section:(NSInteger)sectionNumber delegate: (id <SectionView>) Delegate
{
self = [super initWithFrame:frame];
if (self) {

    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(discButtonPressed:)];
    [self addGestureRecognizer:tapGesture];

    self.userInteractionEnabled = YES;

    self.section = sectionNumber;
    self.delegate = Delegate;

    CGRect LabelFrame = CGRectMake(100, 100, 100, 100);
    LabelFrame.size.width -= 100;
    CGRectInset(LabelFrame, 1.0, 1.0);

    //BUTTON 
    CGRect buttonFrame = CGRectMake(LabelFrame.size.width, 0, 100, LabelFrame.size.height);
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = buttonFrame;
    //[button setImage:[UIImage imageNamed:@"carat.png"] forState:UIControlStateNormal];
    //[button setImage:[UIImage imageNamed:@"carat-open.png"] forState:UIControlStateSelected];
    [button addTarget:self action:@selector(discButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:button];
    self.discButton = button;

    //My IMAGE
    NSString *imageName = @"gradient1.png";
    UIImage *myImage = [UIImage imageNamed:imageName];
    UIImageView *sectionHeaderView = [[UIImageView alloc] initWithImage:myImage];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:myImage];
    imageView.frame = CGRectMake(20,50,100,100);
    [self addSubview:sectionHeaderView];
    self.headerBG = sectionHeaderView;

    //HEADER LABEL
    UILabel *label = [[UILabel alloc] initWithFrame: CGRectMake(22, 12, sectionHeaderView.frame.size.width, 35.0)];
    label.textAlignment = NSTextAlignmentLeft;
    label.backgroundColor = [UIColor clearColor];
    label.textColor = [UIColor whiteColor];
    label.shadowColor = [UIColor darkGrayColor];
    label.shadowOffset = CGSizeMake(0.0, -1.0);
    label.text = title;
    label.font = [UIFont fontWithName:@"AvenirNext-Bold" size:20.0];
    sectionHeaderView.backgroundColor = [UIColor clearColor];
    //label.textAlignment = UITextAlignmentLeft;
    [self addSubview:label];
    self.sectionTitle = label;
}

return self;
}

I have a custom image on the cell @"gradient1.png" but I don't seem to be able to resize it? Here is the header code in the UITableViewController:

    - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:   (NSInteger)section
  {
SectionInfo *array  = [self.sectionInfoArray objectAtIndex:section];
if (!array.sectionView)
{
    NSString *title = array.category.name;
    array.sectionView = [[SectionView alloc] initWithFrame:CGRectMake(0, 10, self.tableView.bounds.size.width, 0) WithTitle:title Section:section delegate:self];
}
return array.sectionView;
}

Sorry if this is a trivial question, your help is greatly appreciated!

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
luliger
  • 33
  • 1
  • 6

1 Answers1

0

I don't see where you are trying to resize the image so I can't offer any help in why it is not resizing, but I found this confusing:

//My IMAGE
    NSString *imageName = @"gradient1.png";
    UIImage *myImage = [UIImage imageNamed:imageName];
    UIImageView *sectionHeaderView = [[UIImageView alloc] initWithImage:myImage];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:myImage];
    imageView.frame = CGRectMake(20,50,100,100);
    [self addSubview:sectionHeaderView];
    self.headerBG = sectionHeaderView;

In this part of code you create two imageviews, then you resize one and add the other to the cell (I'm assuming cell) subviews. Is it possible that you are trying to resize the view that you never added as a subview of the cell?

Also, resizing should happen inside - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath.

Make sure that you are resizing the proper view, ten make sure you are resizing it in the proper place.

Putz1103
  • 6,211
  • 1
  • 18
  • 25
  • thank you so much! i was trying to resize the imageView frame that is not in the cell, very stupid – luliger Jan 31 '13 at 16:36
  • could you possibly help me i with another question, again fairly simple.. how can I have different pictures for different headers? – luliger Jan 31 '13 at 16:37
  • You have your array of which you are populating your tableview. Just do a conditional statement based upon something in that array. Say if my data says something `UIImage *myImage = [UIImage imageNamed:@"someImage];`, else if my data says something else `UIImage *myImage = [UIImage imageNamed:@"somethingElse];` – Putz1103 Jan 31 '13 at 16:46
  • Thanks again, took a while to find a variable, then saw sectionNumber, obvious! – luliger Jan 31 '13 at 17:50