Here is my code:
- (void)loadView {
//hard coded array of content for each site
// CC
NSMutableArray *allccContent = [[NSMutableArray alloc] init];
NSString *cc1 = @"House Model";
NSString *cc2 = @"James Dexter History";
[allccContent addObject: cc1];
[cc1 release];
[allccContent addObject: cc2];
[cc2 release];
// FC
NSMutableArray *allfcContent = [[NSMutableArray alloc] init];
NSString *fc1 = @"Ghost House";
NSString *fc2 = @"Franklins Letters";
NSString *fc3 = @"Franklins Business";
[allfcContent addObject: fc1];
[fc1 release];
[allfcContent addObject: fc2];
[fc2 release];
[allfcContent addObject: fc3];
[fc3 release];
// PC
NSMutableArray *allphContent = [[NSMutableArray alloc] init];
NSString *ph1 = @"Changing Occupancy";
NSString *ph2 = @"Sketches";
NSString *ph3 = @"Servant House";
NSString *ph4 = @"Monument";
NSString *ph5 = @"Virtual Model";
[allphContent addObject: ph1];
[ph1 release];
[allphContent addObject: ph2];
[ph2 release];
[allphContent addObject: ph3];
[ph3 release];
[allphContent addObject: ph4];
[ph4 release];
[allphContent addObject: ph5];
[ph5 release];
// Each content page's view
//UIView *ccContent = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
UIView *fcContent = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
UIView *phContent = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
//ccContent.backgroundColor = [UIColor whiteColor];
fcContent.backgroundColor = [UIColor whiteColor];
phContent.backgroundColor = [UIColor whiteColor];
//[ccContent addSubview:[SiteOneController myNavBar1:@"Constitution Center Content"]];
[fcContent addSubview:[SiteOneController myNavBar1:@"Franklin Court Content"]];
[phContent addSubview:[SiteOneController myNavBar1:@"Presidents House Content"]];
//allocate the view
self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
//set the view's background color
self.view.backgroundColor = [UIColor whiteColor];
[self.view addSubview:[SiteOneController myNavBar1:@"Sites"]];
NSMutableArray *sites = [[NSMutableArray alloc] init];
NSString *one = @"Constution Center";
NSString *two = @"Franklin Court";
NSString *three = @"Presidents House";
[sites addObject: one];
[one release];
[sites addObject: two];
[two release];
[sites addObject: three];
[three release];
NSString *ccName = @"Constitution Center";
NSString *fcName = @"Franklin Court";
NSString *element;
int j = 0;
for (element in sites)
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//setframe (where on screen)
//separation is 15px past the width (45-30)
button.frame = CGRectMake(a, b + (j*45), c, d);
[button setTitle:element forState:UIControlStateNormal];
button.backgroundColor = [SiteOneController myColor1];
/*- (void) fooFirstInput:(NSString*) first secondInput:(NSString*) second {
NSLog(@"Logs %@ then %@", first, second);
}
- (void) performMethodsViaSelectors {
[self performSelector:@selector(fooNoInputs)];
[self performSelector:@selector(fooOneInput:) withObject:@"first"];
[self performSelector;@selector(fooFirstInput:secondInput:) withObject:@"first" withObject:@"second"];*/
//UIView *old = self.view;
if (element == ccName) {
[button addTarget:self action:@selector(showCCView:)
forControlEvents:UIControlEventTouchUpInside];
}
else if (element == fcName) {
}
else {
}
[开发者_开发百科self.view addSubview: button];
j++;
}
}
// This method show the content views for each of the sites.
+ (void) showCCView:(id) sender {
NSLog(@"CC CLICKED");
//UIView *current = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
//[current addSubview:[SiteOneController ccContent]];
}
Now why isn't the showCCView method getting called when the button is clicked? What am I doing wrong?
+ (void) showCCView:(id) sender {
NSLog(@"CC CLICKED");
//UIView *current = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
//[current addSubview:[SiteOneController ccContent]];
}
Because that's a class method, not an instance method. Change the +
to a -
.
精彩评论