get NSString from UITextField - objective-c

I'm trying to write a little weightwatchers points calculator app for myself. I know you can just download one from the appstore but i am trying to learn objective-c and thought this would be a fairly easy first app. I just want to use text entered into a textbox and save it as a variable and use said variable to perform basic math with the intValues. I've tried using the 'text' property of UITextField with no luck, could someone help and tell me what i've done wrong here? well this is awkward...it seems i forgot to tell you what the problem is. i've included the errors i'm receiving on their corresponding lines. What i'm getting out of these errors is that i shouldn't be using the "NSString" to define my variables, maybe "int" instead?
.h file:
#import <UIKit/UIKit.h>
#class FirstViewController;
NSString*txtProtein = nil;
NSString *txtCarbs = nil;
NSString *txtFat = nil;
NSString *txtFiber = nil;
NSString *txtPoints = nil;
NSString *txtproteinCalc = nil;
NSString *txtcarbCalc = nil;
NSString *txtfatCalc = nil;
NSString *txtfiberCalc = nil;
#interface AppDelegate : NSObject
<UIApplicationDelegate> {
UIWindow *window;
FirstViewController
*viewController;
UITextField *protein;
UITextField *carbs;
UITextField *fat;
UITextField *fiber;
UITextView *points;
}
#property (nonatomic, retain)
IBOutlet UIWindow *window;
#property (nonatomic, retain)
IBOutlet FirstViewController *viewController;
#end
and the .m file:
#import "FirstViewController.h"
#import "AppDelegate.h"
#implementation AppDelegate
#synthesize window;
#synthesize viewController;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//Here is where all of the textboxes are defined.
//All of the strings are in the viewController.h
//This is the protein part
txtProtein = [[[UITextField alloc] initWithFrame:CGRectMake(10.0, 10.0, 50.0, 25.0)]; (expected identifier)
txtProtein.backgroundColor = [UIColor whiteColor]; (property "backgroundcolor" not found on object of type 'NSString')
txtProtein.placeholder = #"Protein"; (property "placeholder" not found on object of type 'NSString')
[viewController.view addSubview:txtProtein]; (property 'view' can not be found in forward class object "FirstViewController")
//This is the carbs part
txtCarbs = [[[UITextField alloc] initWithFrame:CGRectMake(30.0, 10.0, 50.0, 25.0)];
txtCarbs.backgroundColor = [UIColor whiteColor];
txtCarbs.placeholder = #"Carbs";
[viewController.view addSubview:txtCarbs];
//This is the Fat part
txtFat = [[[UITextField alloc] initWithFrame:CGRectMake(50.0, 10.0, 50.0, 25.0)];
txtFat.backgroundColor = [UIColor whiteColor];
txtFat.placeholder = #"Fat";
[viewController.view addSubview:txtFat];
//This is the Fiber
txtFiber = [[[UITextField alloc] initWithFrame:CGRectMake(70.0, 10.0, 50.0, 25.0)];
txtFiber.backgroundColor = [UIColor whiteColor];
txtFiber.placeholder = #"Fiber";
[viewController.view addSubview:txtFiber];
//Total Points
txtPoints = [[[UITextField alloc] initWithFrame: CGRectMake(150.0, 10.0, 50.0, 25.0)]autorelease];
txtPoints.backgroundColor = [UIColor greenColor];
txtPoints.editable = NO;
[viewController.view addSubview:txtPoints];
//Protein divided by 10.9375
txtproteinCalc = [txtProtein.text intValue] / [10.9375];
//Carbs divided by 9.2105
txtcarbCalc = [txtCarbs.text intValue] / [9.2105];
//Fat divided by 3.8889
txtfatCalc = [txtFat.text intValue] / [3.8889];
//Fiber divided by 12.5
txtfiberCalc = [txtFiber.text intValue] / [12.5];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(calculatePoints)
name:UITextFieldTextDidChangeNotification
object:nil];
//Add the view controller's view to the window and display
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
//Make keyboard show up in the Protein (The first) box
[txtProtein becomeFirstResponder];
return YES;
}
#pragma mark -
#pragma mark Memory management
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
/*
Free up as much Memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later/
*/
}
-(void)dealloc {
[txtProtein release];
[txtFiber release];
[txtFat release];
[txtCarbs release];
[txtPoints release];
[viewController release];
[window release];
[super dealloc];
}
#pragma mark -
#pragma mark Other Methods
-(void)calculatePoints {
NSLog(#"Calculating FoodTrakr Value...");
txtPoints.text = #"";
if (txtProtein.text.length > 0 && [txtProtein.text intValue]>0 && txtFiber.text.length >0 && [txtFiber.text intValue]>0 && txtFat.text.length >0 && [txtFat.text intValue]>0 && txtCarbs.text.length >0 && [txtCarbs.text intValue]>0
)
{
int Points = [txtproteinCalc.text intValue] + [txtcarbCalc.text intValue] + [txtfatCalc.text intValue] - [txtfiberCalc.text intValue];
txtPoints.text = [[NSNumber numberWithInt:points] stringValue];
}
}
#end
Thanks in advance for any help!
also, if you guys have any recommended books for learning objective c, i've done some reading but i know i obviously need to read up some more, if you could leave any suggestions that helped you learn that would be awesome. Thanks!

To be blunt, the posted code has a lot of serious issues. Let's start with the immediate compile errors.
You have:
txtProtein = [[[UITextField alloc] initWithFrame:CGRectMake(10.0, 10.0, 50.0, 25.0)]; (expected identifier)
txtProtein.backgroundColor = [UIColor whiteColor]; (property "backgroundcolor" not found on object of type 'NSString')
txtProtein.placeholder = #"Protein"; (property "placeholder" not found on object of type 'NSString')
[viewController.view addSubview:txtProtein]; (property 'view' can not be found in forward class object "FirstViewController")
The first line has one too many open brackets. The other major problem with this is you are creating a UITextField but you are assigning it to a variable for an NSString. Instead of txtProtein you should use your protein variable which has the property type. So the code should be:
protein = [[UITextField alloc] initWithFrame:CGRectMake(10.0, 10.0, 50.0, 25.0)];
protein.backgroundColor = [UIColor whiteColor];
protein.placeholder = #"Protein";
[viewController.view addSubview:protein];
You have the same issues repeated over and over in this code.
The next big issue is why is all of this code in your app delegate? Most, if not all, of this code belongs in the FirstViewController.m file. Your app delegate should not be responsible for setting up the view controller. Let the view controller set itself up.
Next, why do you have all of these global variables?
I suggest you find some good tutorials on Objective-C programming then some good tutorials on iOS app development.

Related

Trying to fix subview flipping and now subview buttons no longer work?

I have a view which includes two subviews. I had it working so that only one subview was shown at a time and each subview had a button and when the button was clicked the subview would flip over and the next subview would appear. The problem was that it appeared as though the entire view was flipping. After reading on this site about how to solve the problem I attempted to add the subviews to a container and flip that instead. However now, although my first subview is showing up when I press the button it no longer flip. It doesn't do anything. I put a log statement in the method which flips the subviews, as well as a breakpoint and as far as I can tell it no longer gets called. I'm very new to xcode and objective c and delegates and I have no idea how to proceed. Any help would be appreciated. Thanks.
I have included the relevant code here:
The header for the ViewController
#interface ExerciseViewController : UIViewController<ExerciseSubViewDelegate>
//stuff for subviews
#property (nonatomic, strong) ExerciseSubViewImage *subViewImage;
#property (nonatomic, strong) ExerciseSubViewText *subViewText;
#property UIView *panel;
#end
This is the code for the ViewController:
#interface ExerciseViewController ()
#end
#implementation ExerciseViewController
#synthesize subViewImage, subViewText;
- (void)viewDidLoad
{
self.subViewImage.delegate = self;
_panel = [[UIView alloc] initWithFrame:CGRectMake(0,0, self.view.bounds.size.width, self.view.bounds.size.height/2)];
_panel.backgroundColor = [UIColor whiteColor];
[self.view addSubview:_panel];
[_panel addSubview:subViewImage];
}
-(ExerciseSubViewImage *)subViewImage
{
if (!subViewImage)
{
CGRect subViewImageFrame = CGRectMake(0,0, _panel.bounds.size.width, _panel.bounds.size.height);
self.subViewImage = [[ExerciseSubViewImage alloc] initWithFrame:subViewImageFrame];
[_panel addSubview:subViewImage];
}
return subViewImage;
}
-(ExerciseSubViewText *)subViewText
{
if (!subViewText)
{
CGRect subViewTextFrame = CGRectMake(0,0, _panel.bounds.size.width, _panel.bounds.size.height);
self.subViewText = [[ExerciseSubViewText alloc] initWithFrame:subViewTextFrame];
self.subViewText.backgroundColor = [UIColor blueColor];
[_panel addSubview:subViewText];
}
return subViewText;
}
-(void)exerciseSubViewImagePressed
{
[UIView transitionWithView:_panel
duration:0.2
options:UIViewAnimationOptionTransitionFlipFromRight
animations:^{
[subViewImage removeFromSuperview];
[_panel addSubview:subViewText];
}
completion: nil];
//This is how I did it before I added the container
/*[UIView transitionFromView:subViewImage
toView:subViewText
duration:0.2
options:UIViewAnimationOptionTransitionFlipFromRight
completion:nil];
self.subViewText.delegate = self;*/
NSLog(#"Ipushedtheimage");
}
-(void)exerciseSubViewTextPressed
{//I haven't updated this yet
[UIView transitionFromView:subViewText
toView:subViewImage
duration:0.2
options:UIViewAnimationOptionTransitionFlipFromRight
completion:nil];
self.subViewImage.delegate = self;
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
subViewImage = nil;
subViewText = nil;
}
#end
This is the code for the delegate
#import
#protocol ExerciseSubViewDelegate <NSObject>
-(void) exerciseSubViewImagePressed;
-(void) exerciseSubViewTextPressed;
#end
I am also added the code for the first subview:
#import
#import "ExerciseSubViewDelegate.h"
#interface ExerciseSubViewImage : UIView
#property (nonatomic, strong) UIButton *button;
#property (nonatomic, assign) id<ExerciseSubViewDelegate>delegate;
#property (strong, nonatomic) UIImageView *exerciseImageView;
#end
#import "ExerciseSubViewImage.h"
#import "UIImage+animatedGIF.h"
#implementation ExerciseSubViewImage
#synthesize button;
#synthesize delegate;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
//Initialization code
self.button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
CGRect buttonFrame = CGRectMake(50,200,100,35);
self.button.frame = buttonFrame;
[self.button setTitle:#"Image"forState:UIControlStateNormal];
[self.button addTarget:self
action:#selector(buttonTouched)
forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.button];
_exerciseImageView = [[UIImageView alloc] initWithFrame:CGRectMake(50,20,160,158)];
NSURL *url = [[NSBundle mainBundle] URLForResource:#"AppleLogo" withExtension:#"gif"];
_exerciseImageView.image = [UIImage animatedImageWithAnimatedGIFURL:url];
[self addSubview:self.exerciseImageView];
}
return self;
}
-(void)buttonTouched
{
NSLog(#"imagebuttonpressed");
[self.delegate exerciseSubViewImagePressed];
}
Again, any help would be appreciate. I know I'm probably just not understanding something simple.
Ok. This took me all weekend but I finally figured it out on my own. I thought I would shere the answer here in case anyone else ever has a similar problem. After trying several other approaches I finally went back to the approach I used here and started inserting a whole bunch of NSLogs to determine the order that every thing was executing in. What I finally ended up doing was changing this: (all in the top ViewController)
self.subViewImage.delegate = self;
_panel = [[UIView alloc] initWithFrame:CGRectMake(0,0, self.view.bounds.size.width, self.view.bounds.size.height/2)];
_panel.backgroundColor = [UIColor whiteColor];
[self.view addSubview:_panel];
[_panel addSubview:subViewImage];
to this:
//create panel
_panel = [[UIView alloc] initWithFrame:CGRectMake(0,0, self.view.bounds.size.width, s self.view.bounds.size.height/2)];
_panel.backgroundColor = [UIColor whiteColor];
[self.view addSubview:_panel];
[_panel addSubview:subViewImage];
//Set the subview delegates
self.subViewImage.delegate = self;
self.subViewText.delegate = self;

EXC_BAD_ACCESS in UIWebView delegate

I've got a problem - I'm getting EXC_BAD_ACCESS when trying to set UIWebView.delegate = self;
My code:
vkLogin.h -
#import UIKit/UIKit.h
#interface vkLogin : UIViewController <UIWebViewDelegate>
{
UIWebView *authBrowser;
UIActivityIndicatorView *activityIndicator;
}
#property (nonatomic, retain) UIWebView *authBrowser;
#property (nonatomic, retain) UIActivityIndicatorView *activityIndicator;
#end
vkLogin.m -
#import "vkLogin.h"
#import "bteamViewController.h"
#implementation vkLogin
#synthesize authBrowser;
- (void) viewDidLoad
{
[super viewDidLoad];
activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activityIndicator.center = CGPointMake(self.view.bounds.size.width / 2, self.view.bounds.size.height / 2);
activityIndicator.autoresizesSubviews = YES;
activityIndicator.hidesWhenStopped = YES;
[self.view addSubview: activityIndicator];
[activityIndicator startAnimating];
authBrowser = [[UIWebView alloc] initWithFrame:self.view.bounds];
authBrowser.delegate = self;
authBrowser.scalesPageToFit = YES;
[self.view addSubview:authBrowser];
NSString *authLink = #"http://api.vk.com/oauth/authorize?client_id=-&scope=audio&redirect_uri=http://api.vk.com/blank.html&display=touch&response_type=token";
NSURL *url = [NSURL URLWithString:authLink];
[authBrowser loadRequest:[NSURLRequest requestWithURL:url]];
}
- (void) webViewDidFinishLoad:(UIWebView *)authBrowser
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Lol" message:#"OLOLO" delegate:self cancelButtonTitle:#"Okay" otherButtonTitles:nil, nil];
[alert show];
}
#end
So, if i'm commeting delegate string - everything working fine, but I didn't recieve my webViewDidFinishLoad event.
What I'm doing wrong?
The error isn't in the code you have posted. Your zombie message is saying your reference to vkLogin is bad. So you need to look at whatever class creates and holds a reference to your vkLogin class.
That class should be doing something like a vkLogin *foo = [[vkLogin alloc] init];
Update:
Based on your comments it looks like you are creating a local variable for vkLogin. It would be most useful to see the code creates and uses vkLogin and how it's called. Barring that, here are a few guesses.
You are called the method which creates and adds vkLogin to a subView more than once. (Each time would create a new instance).
You have some sort of call back which can occur after vkLogin has been removed.
My guess is vkLogin should be a property in your class, not a local method variable.
in your .h you would add
#proprerty (strong, nonatomic) vkLogin *vk;
and in your .m file you could refer to it as self.vk so you'd create it and add it as a subview like:
self.vk = [[vkLogin alloc] init];
[self.view addSubview:self.vk];
On a side note, convention says we should start class names with a capital letter, so you'd name the class VkLogin which would make it easily distinguishable from a variable named vkLogin (but worry about that after you solve the problem)

Cannot set property of UIImageView subclass

I've subclassed UIImageView, it's called ACCascadeImageView.
#interface ACCascadeImageView : UIImageView{
BOOL isSpotlight;
}
#property (assign, nonatomic) BOOL isSpotlight;
-----
#implementation ACCascadeImageView
#synthesize isSpotlight;
I then create instances like so, and add a gesturerecognizer..
ACCascadeImageView *imageview =
[[ACCascadeImageView alloc] initWithFrame:imageframe];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleSingleTap:)];
[imageview addGestureRecognizer:singleTap];
In the handleSingleTap method, I loop through my UIScollView subviews, and I try to do this for each one...
(imageview in this scope is [gestureRecognizer view])
[imageview setIsSpotlight:NO];
But I get this...
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '-[UIImageView setIsSpotlight:]: unrecognized selector sent to instance 0x6888be0'
Why has my ACCascadeImageView suddenly become UIImageView? I apologize if I'm doing something stupid, but I've subclassed UIImageView before just fine. I'm confused.
I should say that I've NSLog'd [imageview class] and I get, "ACCascadeImageView".
Here's the problem:
NSArray *cascadeImages = [PhotoCascade subviews];
for (ACCascadeImageView *v in cascadeImages){
NSLog(#"RESPONDS: %d", [v respondsToSelector:#selector(setIsSpotlight:)]);
[v setIsSpotlight:NO];
}
I get :
RESPONDS: 1
RESPONDS: 0
Then it dies.
You can't be sure [gestureRecognizer view] is your UIImageView. To check this try NSLog(#"view: %#", [gestureRecognizer.view class]);. My tests says it's just UIView.
If you're adding gesture recognizer to your image view the selector will be fired only when the user taps this view. So you could omit those checks at all.
By your results, and since you only test once per object, it seems the first object in the array is your custom subview, but the second is not. Maybe somehow one of the objects in cascadeImages isn't an ACCascadeImageView. Step through the array and perform introspection on each one, logging the results, to make sure the array only contains ACCascadeImageViews.
You're saying that your handleSingleTap is returning TRUE in response to respondsToSelector:#selector(setIsSpotlight:), but then when you try to use setIsSpotlight, it fails? That is a mystery.
For example, I've created this super simple example, and it works as you'd expect:
#import "ViewController.h"
#interface Test : UIImageView
#property (assign, nonatomic) BOOL isSpotlight;
#end
#implementation Test
#synthesize isSpotlight;
#end
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
Test *test = [[Test alloc] initWithFrame:self.view.frame];
[self.view addSubview:test];
test.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleSingleTap:)];
[test addGestureRecognizer:tap];
}
- (void)handleSingleTap:(UIGestureRecognizer *)sender
{
Test *imageview = (Test *)[sender view];
NSLog(#"%s %d", __FUNCTION__, [imageview respondsToSelector:#selector(setIsSpotlight:)]);
[imageview setIsSpotlight:NO];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
#end
The problem has to be something simple, but with limited code snippets provided in your question, it's not obvious what the problem is. But the code you've provided above would not manifest the sort of problem you describe. There must be some rogue UIImageView in your app!

when i release an NSMutableArray that i allocate and initiate, my code breaks

with this code, i want to add an image at the place the user taps. i want to add a new one for each tap.
-(void) foundDoubleTap:(UITapGestureRecognizer *) recognizer
{
UIView *piece = recognizer.view;
CGPoint locationInView = [recognizer locationInView:piece];
UIImageView *testPoint = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"inner-circle.png"]];
testPoint.frame = CGRectMake(0, 0, 20, 20);
testPoint.center = CGPointMake(locationInView.x, locationInView.y);
[self.imageView addSubview:testPoint];
NSMutableArray *tempTestPointArray = [[NSMutableArray alloc] initWithArray:testPointArray];
[tempTestPointArray addObject:testPoint];
testPointArray = tempTestPointArray;
NSLog(#"testPointArray: %#", testPointArray);
CGRect myRect = CGRectMake((testPoint.center.x + 12), (testPoint.center.y + 12), 10, 10);
UILabel *myLabel = [[UILabel alloc] initWithFrame:myRect];
myLabel.text = [NSString stringWithFormat:#"Point %d", [testPointArray count]];
myLabel.font = [UIFont fontWithName:#"Trebuchet MS" size:10];
[myLabel sizeToFit];
[imageView addSubview:myLabel];
[myLabel release];
[testPoint release];
//[tempTestPointArray release];
}
why is it that when i release tempTestPointArray, my code breaks when i implement a second tap? it crashes on:
NSMutableArray *tempTestPointArray = [[NSMutableArray alloc] initWithArray:testPointArray];
when i comment out the release for it, the Analyzer does not flag it as a leak. what happened to the rule, if you alloc/init it, you have to release it?
EDIT: adding .h file
.h file:
#interface TestPointMapViewController : UIViewController <UIScrollViewDelegate, UITextFieldDelegate>
{
//other code
NSArray *testPointArray;
}
//other code
#property (nonatomic, retain) NSArray *testPointArray;
//other code
#end
and then #synthesize testPointArray in .m file.
Your testPointArray is not assigning to a property, it is a plain ivar. Doing the line
testPointArray = tempTestPointArray;
Is leaking whatever is previously in testPointArray. Declare testPointArray as a retained property and change to.
self.testPointArray = tempTestPointArray;
Then keep the [tempTestPointArray release];
EDIT:
So the reason why this code is failing has to do with the magic of properties. The following code is equivalent.
self.testPointArray = tempTestPointArray;
[self setTestPointArray:tempTestPointArray];
When you do the #sythesize testPointArray; it is generating a setter method similar to this:
- (void)setTestPointArray:(NSMutableArray *)array {
id temp = testPointArray;
testPointArray = [array retain];
[temp release];
}
So when you don't use the property notation self.testPointArray you are not retaining the variable correctly. You are also losing a reference to a retained object, which is now a leak.
That make sense? If not please review this.
http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/objectiveC/Chapters/ocProperties.html#//apple_ref/doc/uid/TP30001163-CH17-SW1

Issue with multiple instances of same UIView object

I've got a problem at programming for iOS. Already looked for some similar problems but haven't found anything yet.
I'm creating at least 8 custom UIViews. As you can see in the appended code i'm running through a loop creating one instance per round. The reference of every object is on a different space in the memory but when i change a value in one object it only affects the object that has been created in the last loop-round (last created instance).
Any Ideas?
PadView.h:
#import <UIKit/UIKit.h>
#interface PadView : UIView {
}
- (void)setText:(NSString*)text;
#end
PadView.m:
#import "PadView.h"
#import "AVFoundation/AVFoundation.h";
#implementation PadView
AVAudioPlayer *player;
UILabel *label;
- (void)setText:(NSString*)text {
label.text = text;
}
- (void)initialize {
label = [[ UILabel alloc ] initWithFrame:CGRectMake(0.0, 93.0, 107.0, 13.0)];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:9];
label.textAlignment = UITextAlignmentCenter;
label.text = #"Empty";
[self addSubview:label];
[label release];
}
- (id) initWithCoder:(NSCoder *)aCoder {
if (self = [super initWithCoder:aCoder]) {
[self initialize];
}
return self;
}
- (id) initWithFrame:(CGRect)rect {
if (self = [super initWithFrame:rect]) {
[self initialize];
}
return self;
}
- (void)dealloc {
[super dealloc];
}
#end
Create the Objects:
NSMutableArray *pads = [[NSMutableArray alloc] initWithCapacity:8];
for (int i = 0; i < 8; i++) {
PadView *pad = [[PadView alloc] initWithFrame:CGRectMake(0.0, i*150, 107.0, 107.0)];
[padsView addSubview:pad];
[pads addObject:pad];
}
Call setText:
PadView *pad = [pads objectAtIndex:5];
[pad setText:#"test"];
Your variables:
AVAudioPlayer *player;
UILabel *label;
are defined in the #implementation block, so they are effectively global variables (in the C sense).
So basically, all your instances of PadView will change the same UILabel when you set its text property (which explains the behavior you are seeing).
I'm lacking some context, but it seems that you want label to be an instance variable instead (and I'd assume player as well). If that's the case, you need to declare them in the #interface block as follows:
#interface PadView : UIView {
AVAudioPlayer *player;
UILabel *label;
}
- (void)setText:(NSString*)text;
#end
pads is not initialized
NSMutableArray *pads = [[NSMutableArray alloc] initWithCapacity:8];
and you must release pad after adding as subview and to the array
By convention the class should be named PadView, not padView
edit
for(padView *pad in pads){
//manipulate each pad
}
//manipulate a certain pad
padView *pad = [pads objectAtIndex:5];
pad. //...