作成したボタンを配列に追加してから、それらのボタンを配列から削除しようとしています。配列が null を返し続けるので、ボタンが配列に追加されていないように感じますか?
私は初心者です。Xcode 4.3 を使用しています。これが私のコードです:
//
// MainViewController.h
// Test-Wards
//
// Created by Dayle Pearson on 5/12/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "FlipsideViewController.h"
@interface MainViewController : UIViewController <FlipsideViewControllerDelegate>
{
/*This stuff creates a timer */
IBOutlet UILabel *opponentsBlue;
NSTimer *timer;
int redBlue;
/*Stuff for making a label creator */
CGPoint startPoint;
int xStuff, yStuff;
/*array for storing wards*/
NSMutableArray *wardArray;
}
@property CGPoint startPoint;
- (IBAction)startRedBlue:(id)sender;
- (IBAction)removeWard:(id)
sender;
- (void)countdown;
@end
//
// MainViewController.m
// Test-Wards
//
// Created by Dayle Pearson on 5/12/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "MainViewController.h"
@interface MainViewController ()
@end
@implementation MainViewController
@synthesize startPoint;
- (void)countdown
{
if (redBlue < 2) {
[timer invalidate];
timer = nil;
}
redBlue -= 1;
opponentsBlue.text = [NSString stringWithFormat:@"%i", redBlue];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *theTouch = [touches anyObject];
startPoint = [theTouch locationInView:self.view];
}
- (IBAction)startRedBlue:(id)sender
{
UIButton *wardButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
wardButton.frame = CGRectMake((startPoint.x - 5), (startPoint.y - 5), 10, 10);
[wardButton setTitle:@"180" forState:UIControlStateNormal];
//add targets and actions
/*[wardButton addTarget:self action:@selector() forControlEvents:<#(UIControlEvents)#>*/
//add to a view
[self.view addSubview:wardButton];
[self->wardArray addObject: wardButton];
NSLog(@"This elemnt = %@", wardArray);
}
- (IBAction)removeWard:(id)sender
{
[self->wardArray removeLastObject];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
#pragma mark - Flipside View
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller
{
[self dismissModalViewControllerAnimated:YES];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showAlternate"]) {
[[segue destinationViewController] setDelegate:self];
}
}
@end