I have made the basic build and it includes a picker. So whatever units of conversion the user selects from the picker, the labels should be updated to show the names of the units for that conversion and once the user enters the number in the text box and hits the button, the answer should be displayed in the second text box. Now the code executes, but the problem is no matter what I pick in the picker, it always does the weight conversion. I know I need a switch statement in there, but I'm not sure how or where I need to implement it.
Another problem is that the labels update, but only when the "Convert" button is pressed, so please help me fix this.
This is my ViewController.h file
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
<UIPickerViewDelegate, UIPickerViewDataSource> {
IBOutlet UITextField *field1;
IBOutlet UITextField *field2;
IBOutlet UIPickerView *picker;
IBOutlet UILabel *label1;
IBOutlet UILabel *label2;
}
#property (weak, nonatomic) IBOutlet UILabel *textLabelData1;
#property (weak, nonatomic) IBOutlet UILabel *textLabelData2;
#property (nonatomic, retain) UIPickerView *picker;
-(IBAction) currencyConvert:(id)sender;
-(IBAction) weightConvert:(id)sender;
-(IBAction) distanceConvert:(id)sender;
#end
This is my ViewController.m file
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize picker;
static NSString *pd[3] = {#"Currency", #"Weight", #"Speed"};
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark UIPickerViewDelegate & UIPickerViewDataSource methods
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{
return 3;
}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:
(NSInteger)row forComponent:(NSInteger)component;
{
return pd[row];
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:
(NSInteger)row inComponent:(NSInteger)component
{
NSLog(#"didSelectRow %li, inComponent: %li", row, component);
}
-(IBAction)currencyConvert:(id)sender
{
if (pd[0])
{
self.textLabelData1.text = #"Dollar";
self.textLabelData2.text = #"Rupees";
float dollar = [[field1 text] floatValue];
float rupees = dollar * 64.15;
[field2 setText: [NSString stringWithFormat: #"%3.3f", rupees]];
}
/* self.textLabelData1.text = #"Dollar";
self.textLabelData2.text = #"Rupees";
float dollar = [[field1 text] floatValue];
float rupees = dollar * 64.15;
[field2 setText: [NSString stringWithFormat: #"%3.3f", rupees]]; */
}
-(IBAction)weightConvert:(id)sender
{
if (pd[1])
{
self.textLabelData1.text = #"Kilogram";
self.textLabelData2.text = #"Lbs";
float kilogram = [[field1 text] floatValue];
float pounds = kilogram * 2.20462;
[field2 setText: [NSString stringWithFormat: #"%3.3f", pounds]];
}
}
-(IBAction)distanceConvert:(id)sender
{
if (pd[2])
{
self.textLabelData1.text = #"Mile";
self.textLabelData2.text = #"Kilometer";
float miles = [[field1 text] floatValue];
float kilometers = miles * 1.60934;
[field2 setText: [NSString stringWithFormat: #"%3.3f", kilometers]];
}
}
/* Pseudocode for switch statement
-- I tried doing this here, but it gives me an
error saying that "row" is undefined. I understand that
it is a local variable, but how else would I write the
switch statement?
Also, is the placement of the switch statement appropriate here
or will I need to implement it in a function?
switch (row)
{
case 1:
call currencyConvert
case2:
call weightConvert
case3:
call distanceConvert
}
*/
The link to the picture of my Main.storyboard
This isn't the ideal UI and creates inefficiencies, but its your app. I just wanted to point out that you might want to spend time working on its design and structure.
As for a solution to your problem, I cant fix everything for you, but I'll point out some things to make it easier for you.
The reason your labels are not updating is because you are not updating anything until you hit the convert button. The below function is where you'll get the event for the picker's new row
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:
(NSInteger)row inComponent:(NSInteger)component
{
NSLog(#"didSelectRow %li, inComponent: %li", row, component);
}
Try this instead:
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:
(NSInteger)row inComponent:(NSInteger)component
{
NSLog(#"didSelectRow %li, inComponent: %li", row, component);
switch (row) {
case 0:
self.textLabelData1.text = #"Dollar";
self.textLabelData2.text = #"Rupees";
break;
case 1:
// and so on
}
}
Your next issue is that you're not telling your "convert" functions what row is currently selected, and your conditional if does nothing.
In obj-c conditional statements used directly on a variable are basically just checks for initialization. if(x) simply means has x been initialized as a variable = true, if not = false. That's probably not the logic you're looking for in this case.
Next, It appears you're trying to link 3 different functions to the same button press? This is where your above if related issue is causing problems, all three functions are firing at the same time... but only one gets the last say. Presumably the one you linked last, though i cant say for sure. I'd suggest a single function that handles the button press and then relays to the correct methods.
Last, you're never telling the functions anything about the state of the picker. You need to set it as an IBOutlet so your variables will have access to it. Then you can use the picker's selected row function to determine which conversion to use.
The things I highlighted will fix your problems, BUT I would highly recommend checking out some tutorials so you'll learn more about why things do what. I'd recommend: https://www.raywenderlich.com/
Hope that helps!
Related
I have no idea how I should correctly name the title but I know exactly what my problem is (I will eventually edit the title later).
I am pretty new to Objective-C and I am still learning.
So, I have a class that contains a tableView (I will call it ClassA) and another with a normal UIView (ClassB). What I want to do, is to let a button appear when a row is selected.
I created in my ClassB.h file:
+(id)sharedInstance;
#property (retain, nonatomic) IBOutlet UIButton *btn;
-(void) showBtn :(BOOL) show;
And in my ClassB.m file:
#synthesize btn;
static ClassB *this = nil;
(+id) sharedInstance {
if(!this) {
#synchronized (self) {
this = [[ClassB alloc] init];
}
}
return this;
}
-(void)viewDidLoad {
[self showBtn:NO] //because I only want to let it appear when a row is selected.
[self.view addSubview:btn];
}
-(void) showBtn :(BOOL) show { // I called this method in classA.
if (show == NO) {
btn.hidden = YES;
} else {
btn.hidden = NO;
}
}
So when I launch my app, the button is hidden and stays hidden when I select a row. I debugged, and found that btn is nil when I called the method in ClassA. After some research, I found that the method is called for another instance, so here my question, what can I do, to get it called for the right instance?
EDIT
Here part of my ClassA.m
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger row = [indexPath row];
[[ClassB sharedInstance] showBtn:YES];
}
Observation: The ClassB is a UIViewController which is wrong. UIViewControllers have viewDidLoad.
Implementation Suggestion:
The correct implementation for the requirement would be that you create a custom cell with a button. Hide the button in awakeFromNib method. in didSelectRowAtIndex set the cell.button.isHidden = YES.
This should alone take care of the requirement mentioned above.
I am testing a simple UIPickerView app so that I can use it as a class in my project...
the code works beautifully with ARC but as soon as I turn ARC off the build succeeds but crashes when I click on the display of the picker...the error displayed is "EXC_BAD_ACCESS(code=2, address=oxc)" at the line
return [pickerData1 objectAtIndex:row];
will be extremely grateful if someone can help...I have spent more than 7 working days [60hours+] trying all sorts of options given on the stackoverflow website but just can't get around the issue...needless to say I am trying to learn...
...i have learnt this much that there is a problem with the array...it is being released whereas it should be retained till the 'objectAtIndex' call...but I have tried countless ways of going about this none worked...its because i don't have an in-depth understanding of xcode as yet...trying to learn by doing...usually i am successful in figuring out how to apply sample code in my project and have successfully completed many complex parts of my project (it is an iPad app that deploys augmented reality technology), but am desperately stuck at this rather simple component...
this is the header file:
#import <UIKit/UIKit.h>
#interface PickerText : UIViewController<UIPickerViewDataSource, UIPickerViewDelegate>
{
NSArray *pickerData1;
}
#property (retain, nonatomic) IBOutlet UIPickerView *picker1;
#property (retain, nonatomic) IBOutlet UIButton *buttonForSelection1;
#end
and this is the implementation file
#import "PickerText.h"
#interface PickerText ()
//set tags to enable future incorporation of multiple pickers
#define kPICKER1COLUMN 1
#define kPICKER1TAG 21
#define kButton1Tag 31
#end
#implementation PickerText
#synthesize picker1;
#synthesize buttonForSelection1;
- (void)viewDidLoad
{
[super viewDidLoad];
// assign data in array
pickerData1 = #[#"[tap to select]", #"Item 1", #"Item 2", #"Item 3", #"Item 4", #"Item 5", #"Item 6"];
// Connect data
picker1.tag = kPICKER1TAG;
self.picker1.dataSource = self;
self.picker1.delegate = self;
picker1.hidden = YES;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
// set number of columns of data in picker view
- (int)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
if (pickerView.tag == kPICKER1TAG)
return kPICKER1COLUMN;
else { return 0; }
}
// The number of rows of data
- (int)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
if (pickerView.tag == kPICKER1TAG)
return [pickerData1 count];
else { return 0; }
}
// The data to return for the row and component (column) that's being passed in (ie set the data in picker view)...
//method using NSString
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
if (pickerView.tag == kPICKER1TAG)
return [pickerData1 objectAtIndex:row];
else { return 0; }
}
// Capture the picker view selection
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if (pickerView.tag == kPICKER1TAG)
{
NSString *selection1 = [pickerData1 objectAtIndex:[picker1 selectedRowInComponent:0]];
//check selection
NSLog(#"%#", selection1);
//change display text on button
[buttonForSelection1 setTitle:selection1 forState:UIControlStateNormal];
[buttonForSelection1 setTitle:selection1 forState:UIControlStateSelected];
}
//to hide picker view after selection
pickerView.hidden=YES;
}
- (IBAction)showPicker:(id)sender
{
if ([sender tag] == kButton1Tag)
{
picker1.hidden = NO;
}
}
#end
many thanks in advance!!
And in case if you want to know what the issue is with ARC turned off. The Problem is here:(1)
#interface PickerText : UIViewController<UIPickerViewDataSource, UIPickerViewDelegate>
{
NSArray *pickerData1;
}
and here(2) -
pickerData1 = #[#"[tap to select]", #"Item 1", #"Item 2", #"Item 3", #"Item 4", #"Item 5", #"Item 6"];
You see, in ARC the default association is strong so when you write the second line, THE pickerData1 holds a strong reference to the autorelease array and it all works properly. But without ARC the default association is assign hence , since in line 2 you have assigned an autorelease array (which is getting released at some later point of time), you are getting the crash. You can learn the difference between assign and strong in the Apple documents.
Better you change the array to a strong property. Though without ARC, strong will simply mean retain.
Cheers, have fun.
Don't bother turning ARC off. You have the option to enable/disable ARC on a file-by-file basis:
-fobjc-arc to turn ARC on for a file in a project that doesn't work with ARC
-fno-objc-arc vice-versa
I'm trying to learn iOS from an entirely Android background. I would like to build a UIPickerView Util class that can be reused over and over again as a separate class throughout my app and I'm receiving the EXC_BAD_ACCESS message and I'm not sure why. So I have two questions:
I've not seen anything about separating this as a different class, is this because this is an improper way to handle this problem?
What's wrong with this basic (mostly generated) code that would be giving me the EXC_BAD ACCESS message? I've read that this is related to memory issues. I'm using ARC so why is this an issue?
Here are the beginnings of the class that I'm trying to build.
Header file
#import <UIKit/UIKit.h>
#interface PickerTools : UIViewController<UIPickerViewDelegate>
#property (strong, nonatomic)UIPickerView* myPickerView;
-(UIPickerView*)showPicker;
#end
Implementation file
#import "PickerTools.h"
#implementation PickerTools
#synthesize myPickerView;
- (UIPickerView*)showPicker {
myPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 200, 320, 200)];
myPickerView.delegate = self;
myPickerView.showsSelectionIndicator = YES;
return myPickerView;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow: (NSInteger)row inComponent: (NSInteger)component {
// Handle the selection
}
// tell the picker how many rows are available for a given component
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
NSUInteger numRows = 5;
return numRows;
}
// tell the picker how many components it will have
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
// tell the picker the title for a given component
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
NSString *title;
title = [#"" stringByAppendingFormat:#"%d",row];
return title;
}
// tell the picker the width of each row for a given component
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
int sectionWidth = 300;
return sectionWidth;
}
#end
Here's how I'm calling it from a method in a UITableViewController class:
PickerTools *picker = [[PickerTools alloc]init];
[[self view]addSubview:[picker showPicker]];
What are you doing with showPicker? showPicker is misleading because it doesn't actually show. It only returns a pickerView with a frame. At some point you need to add it to a view using addSubview or use a UIPopoverController or something.
If you are just creating your view controller class within the scope of a method, then it is getting released as soon as that method is done running. Then all bets are off. The picker is trying to access the delegate (which is the view controller) but the view controller is nowhere to be found because it was released.
You'll have to post some usage code. By itself, this code should work, but it's how you're using it.
Also, you don't have to use a UIViewController just to "control" a simple view. Consider making a custom class and just sublcass NSObject.
EDIT:
After looking at your posted code my suspicions were correct. You need to "retain" your PickerTools instance. Meaning, you need to save the "picker" variable (misleading again) as a strong property on the calling view controller. It gets released right after you're adding the pickerview as a subview. The pickerView is alive because it's being retained by it's superview but the object that holds it (the delegate "picker") is dead. Make sense?
I am currently a new developer, and I came across this error; SIGABRT. I have tried developing many apps, and a lot of them get this error. I am developing a sound matching educational app for little kids where they use one picker view in Xcode to match an animal and their sound. My code is as follows:
ViewController.m
#define componentCount 2
#define animalComponent 0
#define soundComponent 1
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize lastAction;
#synthesize matchResult;
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
NSString *actionMessage;
NSString *matchMessage;
int selectedAnimal;
int selectedSound;
int matchedSound;
if (component==animalComponent) {
actionMessage=[[NSString alloc]
initWithFormat:#"You Selected The Animal Named '%#'!",
[animalNames objectAtIndex:row]];
} else {
actionMessage=[[NSString alloc]
initWithFormat:#"You Selected The Animal Sound '%#'!",
[animalSounds objectAtIndex:row]];
}
selectedAnimal=[pickerView selectedRowInComponent:animalComponent];
selectedSound=[pickerView selectedRowInComponent:soundComponent];
matchedSound=([animalSounds count] - 1) -
[pickerView selectedRowInComponent:soundComponent];
if (selectedAnimal==matchedSound) {
matchMessage=[[NSString alloc] initWithFormat:#"Yes, A '%#' Does Go '%#'!"];
[animalNames objectAtIndex:selectedAnimal],
[animalSounds objectAtIndex:selectedSound];
} else {
matchMessage=[[NSString alloc] initWithFormat:#"No, A '%#' Doesn't Go '%#'!"];
[animalNames objectAtIndex:selectedAnimal],
[animalSounds objectAtIndex:selectedSound];
}
lastAction.text=actionMessage;
matchResult.text=matchMessage;
[matchMessage release];
[actionMessage release];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
if (component==animalComponent) {
return [animalNames objectAtIndex:row];
} else {
return [animalSounds objectAtIndex:row];
}
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
if (component==animalComponent) {
return [animalNames count];
} else {
return [animalSounds count];
}
}
- (void)dealloc {
[animalNames release];
[animalSounds release];
[lastAction release];
[matchResult release];
[super dealloc];
}
- (void)viewDidLoad {
animalNames=[[NSArray alloc]initWithObjects:
#"Cat", #"Dog", #"Snake", #"Cow", #"Horse", #"Pig", #"Duck", #"Sheep", #"Bird",nil];
animalSounds=[[NSArray alloc]initWithObjects:
#"Chirp", #"Baa", #"Quack", #"Oink", #"Nay", #"Moo", #"Hiss", #"Bark", #"Purr",nil];
[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);
}
#end
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate> {
NSArray *animalNames;
NSArray *animalSounds;
IBOutlet UILabel *lastAction;
IBOutlet UILabel *matchResult;
}
#property (nonatomic, retain) UILabel *lastAction;
#property (nonatomic, retain) UILabel *matchResult;
#end
Where The SIGABRT Is
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char *argv[])
{
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
//at end of row of code above this, there was the error message: signal SIGABRT
}
}
Anyways, I absolutely need help on what I should do in order to get rid of this SIGABRT error. Thank you.
You have to identify the line of code that is causing the problem, something we cannot identify from the snippet of code.
You may want to enable exception breakpoints, as they often can identify the precise exact line of code that is causing the exception. When I encounter exceptions in my development, I'll simply add an exception breakpoint on "All" exceptions (see Breakpoint Navigator Help or the screen snapshot below). That way, if I'm running the program through my debugger, when it encounters an exception, it will stop the code at the offending line, greatly simplifying the process of identifying the source of the problem. It doesn't always work perfectly, but it frequently finds the source of the exception more quickly than other techniques.
For a broader discussion on debugging apps (e.g. using the debugger to single step through your code, see the Xcode User Guide: Debug your App. If you know the problem is in this method, you might want to step through your code, line by line, and the problem will become self-evident.
I'd also suggest you check out My App Crashed, Now What on the Ray Wenderlich site.
You seem to have some formatting issues with your match message:
matchMessage=[[NSString alloc] initWithFormat:#"Yes, A '%#' Does Go '%#'!"];
[animalNames objectAtIndex:selectedAnimal],
[animalSounds objectAtIndex:selectedSound];
I'm surprised the compiler will actually compile this, but anyhow - you need to include the selected strings within the method call stringWithFormat:
Try below:
matchMessage = [[NSString alloc] initWithFormat:#"Yes, A '%#' Does Go '%#'!",
[animalNames objectAtIndex:selectedAnimal],
[animalSounds objectAtIndex:selectedSound]
];
Your compiler will definitely be giving you a warning about this. So your first step should always be to fix the compiler warnings. It's good practice to turn on the 'Treat warnings as errors' option in build settings. This means that the compiler is very strict about what it will accept and run - which means that you have to fix the warnings. There's really no excuse for having warnings from your compiler.
Read the english before the first call stack. What does it tell you? The most common form of sigabrt is where an IBOutlet gets deleted in the .h file and the outlet connection is still there in the storyboard. To solve this, delete all outlet connections in the storyboard, rewrite the IBOutlets, and link them over again.
For one of my last school projects, I am creating an iPad/iPhone application. For some days now I've been working on an issue with a certain memory leak. My application starts out on a specific view-controller (VCMainStatistics_iPad). From there, I push another view-controller (VCSocialMedia_iPad). Afterwards, I go back to the first view-controller.
When I repeat this sequence, I notice (by using Instruments - Activity Monitor) that the memory usage of the app keeps increasing. By disabling parts of the code, I eventually found out it has something to do with the pickerView. This code gives no leaks:
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return 0;
}
However, when I increase the number of rows, leaks start emerging (roughly 0.07 MB per row). Obviously, this is why I believe the pickerView is the cause of the leaks. I've been trying to remove the subviews from the pickerView before deallocation, setting pickerView to nil, and lots of other things... nothing fixes the issue. To hopefully make things a bit clearer, I'll post some more code.
The header file:
#import "UniversalViewController.h"
#define DATATYPE_SOCIALMEDIA 0
#interface VCSocialMedia_iPad : UniversalViewController <UIPickerViewDataSource, UIPickerViewDelegate>
{
NSArray *lMediaTypes;
NSMutableArray *lMediaData;
__weak IBOutlet UIPickerView *pkSocialMedia;
__weak IBOutlet UILabel *lblGraph;
}
#end
PickerView delegate methods:
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
// Get key of requested row
NSString *title = [[lMediaTypes objectAtIndex:row] capitalizedString];
// Capitalize first letter
title = [title capitalizedString];
// Return
return title;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
// Make or clear data lists
if( lGraphDayDataX[iSelectedServerIndex][DATATYPE_SOCIALMEDIA] == nil ){
lGraphDayDataX[iSelectedServerIndex][DATATYPE_SOCIALMEDIA] = [[NSMutableArray alloc] init];
}
else{
[lGraphDayDataX[iSelectedServerIndex][DATATYPE_SOCIALMEDIA] removeAllObjects];
}
if( lGraphDayDataY[iSelectedServerIndex][DATATYPE_SOCIALMEDIA] == nil ){
lGraphDayDataY[iSelectedServerIndex][DATATYPE_SOCIALMEDIA] = [[NSMutableArray alloc] init];
}
else{
[lGraphDayDataY[iSelectedServerIndex][DATATYPE_SOCIALMEDIA] removeAllObjects];
}
// Get required key
NSString *dictKey = [lMediaTypes objectAtIndex:row];
if( [dictKey isEqualToString:#"total_views"] ){
return;
}
// Adjust graph label
lblGraph.text = [NSString stringWithFormat:#"Stats from %#", dictKey];
// Get data of selected row
NSArray *mediaData = [lMediaData objectAtIndex:row];
// Add each day to data lists: inversed order
for( int day = [mediaData count]-1; day >= 0; day-- ){
NSDictionary *dayData = [mediaData objectAtIndex:day];
dictKey = #"wpsd_trends_date";
NSString *date = [dayData objectForKey:dictKey];
// Remove 00:00:00
date = [date stringByReplacingOccurrencesOfString:#" 00:00:00" withString:#""];
[lGraphDayDataX[iSelectedServerIndex][DATATYPE_SOCIALMEDIA] addObject:date];
dictKey = #"wpsd_trends_stats";
NSString *stats = [dayData objectForKey:dictKey];
[lGraphDayDataY[iSelectedServerIndex][DATATYPE_SOCIALMEDIA] addObject:stats];
}
// Update the graphs
[self updateGlobalScreen];
}
PickerView datasource methods:
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return [lMediaTypes count];
}
Deallocation:
- (void)dealloc
{
pkSocialMedia = nil;
lblGraph = nil;
lMediaData = nil;
lMediaTypes = nil;
}
I only recently converted the project to Objective-C ARC, so there is a good chance this issue has something to do with my lack of experience with the concept. Apart from that, this is also my first Xcode project ever. Hopefully, someone here can help out: please let me know if I need to post more code to clarify things.
Thanks in advance!
Try removing the -(void)dealloc method. It shouldn't be implemented when you're using ARC. If you aren't using ARC, it needs to call [super dealloc].
Never found the solution itself, so I used a workaround: by replacing the NSPickerView with a NSTableView component, the leak did not occur anymore. For everyone who noticed the issue and tried to find a solution: thank you for trying!
I'm having a similar issue. It only happens when the UIPickerView is outside the bounds. The way I fixed it is to never have the UIPickerView move out of bounds (simply fade in and fade out to unhide/hide the UIPickerView). Probably a bug in UIKit.