因此,我生动地建立了3个UIButtons(现今),这个地方:
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 *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];
[button addTarget:self action:@selector(showCCView:)
forControlEvents:UIControlEventTouchUpInside];
[button setTag:j];
[self.view addSubview: button];
j++;
}
The @Selector methods is here:
- (void) showCCView:(id) sender {
UIButton *button = (UIButton *)sender;
int whichButton = button.tag;
NSString* myNewString = [NSString stringWithFormat:@"%d", whichButton];
self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
self.view.backgroundColor = [UIColor whiteColor];
UINavigationBar *cc = [SiteOneController myNavBar1:@"Constitution Center Content"];
UINavigationBar *fc = [SiteOneController myNavBar1:@"Franklin Court Content"];
UINavigationBar *ph = [SiteOneController myNavBar1:@"Presidents House Content"];
if (whichButton = 0)
{
NSLog(myNewString);
[self.view addSubview:cc];
}
else if (whichButton = 1)
{
NSLog(myNewString);
[self.view addSubview:fc];
}
else if (whichButton = 2)
{
NSLog(myNewString);
[self.view addSubview:ph];
}
}
现在,正如该方法所示,它正在将正确的ton子印到国家记录仪上,但电子记录仪“Franklin法院”作为标题“Franklin法院”显示一条航标,即使我点击了丁顿0时,它却说“Button 0点击”在哥尔,但如果(Button = 1)代码的话,它仍能做其他工作。
我在这里找不到什么东西?