Search Results

Search found 2 results on 1 pages for 'dxq'.

Page 1/1 | 1 

  • How do I use a UIView subclass as a container?

    - by dxq
    I'm trying to subclass UIView to create a custom view that is essentially a container. The subclass contains a UILabel and a UIImageView- I can't make either of them show up. Here's an example of what I've been trying: In my main view controller: - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { ViewClass *myView = [[ViewClass alloc] initWithFrame:CGRectMake(100, 100, 150, 150)]; [view addSubview:myView]; } return self; } In my UIView subclass: - (id)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { UILabel *word = [[[UILabel alloc] initWithFrame:[self bounds]] autorelease]; word.text = @"WHY ISN'T THIS SHOWING UP!?"; [self addSubview:word]; } return self; } Can anyone explain what I'm doing wrong? I'm way out of practice with UIKit and Obj-C, and I figure I'm probably missing something obvious.

    Read the article

  • Problems Expanding an Array in C++

    - by dxq
    I'm writing a simulation for class, and part of it involves the reproduction of organisms. My organisms are kept in an array, and I need to increase the size of the array when they reproduce. Because I have multiple classes for multiple organisms, I used a template: template <class orgType> void expandarray(orgType* oldarray, int& numitems, int reproductioncount) { orgType *newarray = new orgType[numitems+reproductioncount]; for (int i=0; i<numitems; i++) { newarray[i] = oldarray[i]; } numitems += reproductioncount; delete[] oldarray; oldarray = newarray; newarray = NULL; } However, this template seems to be somehow corrupting my data. I can run the program fine without reproduction (commenting out the calls to expandarray), but calling this function causes my program to crash. The program does not crash DURING the expandarray function, but crashes on access violation later on. I've written functions to expand an array hundreds of times, and I have no idea what I screwed up this time. Is there something blatantly wrong in my function? Does it look right to you? EDIT: Thanks for everyone's help. I can't believe I missed something so obvious. In response to using std::vector: we haven't discussed it in class yet, and as silly as it seems, I need to write code using the methods we've been taught.

    Read the article

1