我对以下代码中存在损坏的原因感到茫然。我几乎从示例中解除了现有的“实现”。但是,当我尝试更改我的选择器控制器的值时,代码崩溃,因为cloudProviders指向一些随机内存。 请指教。
// SettingsViewController.h
#import <UIKit/UIKit.h>
@interface SettingsViewController : UIViewController
<UIPickerViewDelegate, UIPickerViewDataSource>
@property (retain, nonatomic) IBOutlet UIPickerView *picker;
@property (retain, nonatomic) NSArray *cloudProviders;
@end
// SettingsViewController.m
#import "SettingsViewController.h"
@interface SettingsViewController ()
@end
@implementation SettingsViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_cloudProviders = @[@"BOX", @"Yandex", @"Other"];
NSLog(@"Executing viewDidLoad");
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc {
[_picker release];
[super dealloc];
}
#pragma mark -
#pragma mark PickerView DataSource
- (NSInteger)numberOfComponentsInPickerView:
(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{
return _cloudProviders.count;
}
- (NSString *)pickerView:(UIPickerView *)pickerView
titleForRow:(NSInteger)row
forComponent:(NSInteger)component
{
return _cloudProviders[row];
}
#pragma mark -
#pragma mark PickerView Delegate
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
inComponent:(NSInteger)component
{
NSLog(@"Executing didSelectRow");
}
/*
-(IBAction)textFieldReturn:(id)sender
{
[sender resignFirstResponder];
}
*/
@end
此外,人们使用什么工具来跟踪iOS上的内存泄漏?有什么东西可以告诉我谁修改了我的指针?
谢谢
答案 0 :(得分:0)
安娜是对的。 将属性设置为self.cloudProviders可以解决问题。