English 中文(简体)
出入通道
原标题:Bad Access on removing from array

因此,我的密码汇编,在我用X条编码管理我的听器时,它便会发现一吨记忆错误,对坏出入提出抱怨,即对什么意思没有认识。 所有试图这样做的伊玛目都是从我的眼光中去除制造的实验室,在一阵列中使用一种反射剂,这种反射比想象的要困难得多。 我很新,反对任何帮助。

#import "FlipsideViewController.h"

@interface MainViewController : UIViewController <FlipsideViewControllerDelegate> 
{
    /*This stuff creates a timer */
    IBOutlet UILabel *opponentsBlue;
    NSTimer *timer;
    int redBlue;
    int count;
    /*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;
-(id)init;

@end

#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];

}

-(id)init{
    int count = 0;
    return self;
}

- (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];

    if (!wardArray) {
        wardArray = [NSMutableArray array];
    } 
    if (wardArray){
        [self->wardArray addObject: wardButton];
        count++;
    }

    NSLog(@"This elemnt = %@", wardArray);


}
- (IBAction)removeWard:(id)sender 
{

    NSLog(@"The count is %@", count);
    [[wardArray objectAtIndex:count] removeFromSuperview];

    count--;

    NSLog(@"This elemnt = %@", wardArray);


}
- (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
问题回答

我说,这并不是ARC。

Array公司没有保留,因此,它在设立后不久便会处理。

页: 1 这样,它只会泄露记忆,而不是留下一个omb子。

Also you may want to read up on Objective-C memory management.





相关问题
How to change out-of-focus text selection color in Xcode?

Okay, I ll bite. I ve got really pleasant code/window colors set up in Xcode. Ordinarily, my selection color is very visible. When I am doing a project search and iterating through the results, ...

Iphone NSTimer Issue

Hi I am new to objective c. I am trying to make an app for iphone. I have a button on my view, and the click on which the function playSound is called. This is working properly. It does plays the ...

Include a .txt file in a .h in C++?

I have a number of places where I need to re-use some template code. Many classes need these items In a .h could I do something like: #include <xxx.txt> and place all of this code in the ....

Iterating over string/strlen with umlauted characters

This is a follow-up to my previous question . I succeeded in implementing the algorithm for checking umlauted characters. The next problem comes from iterating over all characters in a string. I do ...

Xcode open two editor windows with same file

Is it possible to open the same file in two separate windows in Xcode. I can open a file in one window and the same file in the main Xcode editor window, but I wanted two separate fulltime editor ...

Forcing code signing refresh in Xcode

In our environment, we share resources across multiple projects and platforms. When building for iPhone, only a subset of those resources are needed. Since that subset is still considerable, we have ...

热门标签