Keep getting expression result unused when trying to update UILabel - ios

I'm very new to programming in general. I am trying to update the UILabel "Lives" with the integer life. However I keep getting the warning "expression result unused" in the line
Lives.text = #"",life;
//
// Game.m
// SprinklerDash
#import "Game.h"
#interface Game ()
#end
#implementation Game
-(void)Walk{
Runner.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"Runner1.png"],
[UIImage imageNamed:#"Runner2.png"],
[UIImage imageNamed:#"Runner3.png"],
[UIImage imageNamed:#"Runner4.png"],
[UIImage imageNamed:#"Runner5.png"],
[UIImage imageNamed:#"Runner6.png"],
[UIImage imageNamed:#"Runner7.png"],
[UIImage imageNamed:#"Runner8.png"], nil];
[Runner setAnimationRepeatCount:INFINITY];
Runner.animationDuration = .75;
[Runner startAnimating];
}
-(void)Moving{
Runner.center = CGPointMake(Runner.center.x, Runner.center.y - UpMovement);
if(CGRectIntersectsRect(Runner.frame, Water.frame)){
life = life - 1;
Lives.text = #"",life;
Runner.center = CGPointMake(Runner.center.x, Runner.center.y + 100);
}
}
-(IBAction)StartGame:(id)sender{
Start.hidden=YES;
UpMovement = 3;
[self Walk];
Movement = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:#selector(Moving) userInfo:nil repeats:YES];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end

If Lives is your label, Then it should be as below.
Lives.text =[NSString stringWithFormat:#"%#",life]; /// if life is string
Lives.text =[NSString stringWithFormat:#"%d", life]; /// if life is integer

Replace this with your Method, and it is good to go.
-(void)Moving{
Runner.center = CGPointMake(Runner.center.x, Runner.center.y - UpMovement);
if(CGRectIntersectsRect(Runner.frame, Water.frame)){
life = life - 1;
lives.text = [NSString stringWithFormat:#"%d",life];
// Lives.text = #"",life;
Runner.center = CGPointMake(Runner.center.x, Runner.center.y + 100);
}
}

Related

Why is one of my NSTimer messing up my background movement?

I have two NSTimer. The problem is that my countdown timer messes up my background positioning as soon as the countdown timer stops. The background moves properly up until the point where the background timer stops. Then it will automatically reposition the background to the starting position, which I do not want because it seems glitchy when it happens. I want it to keep flowing smoothly as soon as the countdown timer stops. If I were to take the countdown timer out, the background movement works perfectly. Here is my code:
PlayViewController.h
#import <UIKit/UIKit.h>
#interface PlayViewController : UIViewController
{
int countdownStatus;
IBOutlet UIImageView *background;
NSTimer *backgroundMovement;
NSTimer *gameCountdownTimer;
}
#property (strong, nonatomic) IBOutlet UILabel *countdownLabel;
- (void)backgroundMoving;
- (void)gameCountdown;
#end
PlayViewController.m
#import "PlayViewController.h"
#interface PlayViewController ()
#end
#implementation PlayViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.countdownLabel.text = #"3";
countdownStatus = 2;
gameCountdownTimer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:#selector(gameCountdown) userInfo:nil repeats:YES];
backgroundMovement = [NSTimer scheduledTimerWithTimeInterval:0.01f target:self selector:#selector(backgroundMoving) userInfo:nil repeats:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)backgroundMoving
{
background.center = CGPointMake(background.center.x - 1, background.center.y);
CGRect backgroundFrame = background.frame;
if(backgroundFrame.origin.x < -370)
{
CGRect myFrame = background.frame;
myFrame.origin.x = 0;
myFrame.origin.y = 0;
background.frame = myFrame;
}
}
- (void)gameCountdown
{
if(countdownStatus == 2)
self.countdownLabel.text = #"2";
else if(countdownStatus == 1)
self.countdownLabel.text = #"1";
else
self.countdownLabel.text = #"";
countdownStatus--;
}
#end

Delegate is not responding

I am trying to call another method with Delegate and protocols in my app. I need to send the variable "myData" to another view but for some reasons it doesn't works. I don't know what I am doing wrong with the implementation of delegates and protocols. The delegate never call the action of the protocol.
Sorry I'm new with this.
BLEViewController.h
#import <UIKit/UIKit.h>
#import "BLE.h"
#protocol EnviarDatos <NSObject>
//Metodo que se manda llamar pero se implementa en otra clase
-(void) actualizaDatos:(NSData*)Data;
#end
#interface BLEViewController : UITableViewController <BLEDelegate>
{
//id <EnviarDatos> delegate;
}
#property (nonatomic,assign)id delegate;
#property (nonatomic, retain) NSData *myData;
+ (BLE*) theBLEObject;
- (void) scanForPeripherals;
- (IBAction)connect:(id)sender;
-(void) activaProtocolo;
#end
BLEViewController.m
//
// BLEViewController.m
// DL_RemoteBLE_02
//
// Created by Dave Lichtenstein on 3/16/14.
// Copyright (c) 2014 Dave Lichtenstein. All rights reserved.
//
#import "BLEViewController.h"
static BLE* ble;
static UILabel *statusLabel;
static NSString* connectionStatus = #"Not connected!";
#interface BLEViewController ()
#end
#implementation BLEViewController
#synthesize delegate;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
if(ble==nil)
{
// Create our Bluetooth Low Energy object
//
ble = [[BLE alloc] init];
[ble controlSetup];
ble.delegate = self;
}
// Create a toolbar at the bottom of the screen to show status text, etc.
//
// get screen size
//
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
CGFloat toolbarHeight = 50.0;
CGFloat labelHeight = 50.0;
if(statusLabel==nil) // only create once
{
// create our status label object
//
statusLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, screenHeight-toolbarHeight-labelHeight, screenWidth, labelHeight)];
statusLabel.backgroundColor = [UIColor clearColor];
statusLabel.textColor = [UIColor blackColor];
statusLabel.font = [UIFont boldSystemFontOfSize:15];
statusLabel.text = #"Connection Status:";
}
// create a toolbar
//
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,screenHeight-toolbarHeight,screenWidth,toolbarHeight)];
toolbar.tintColor = [UIColor blackColor];
/*UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 150, 20)];
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor blackColor];
label.font = [UIFont boldSystemFontOfSize:15];
label.text = #"Status:";
UIBarButtonItem *labeltext = [[UIBarButtonItem alloc] initWithCustomView:label];
UIBarButtonItem *button = [[UIBarButtonItem alloc]initWithTitle:#"" style:UIBarButtonItemStyleDone target:self action:nil];
NSArray *items = [NSArray arrayWithObjects:statusLabel, nil];
toolbar.items = items;
*/
[self.view addSubview:statusLabel];
[self.view addSubview:toolbar];
// Update our status label
statusLabel.text = connectionStatus;
_myData = [[NSData alloc]init];
delegate = self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//-------------------------------------------------------
// methods
/////////////////////////////////////////////////////////
+ (BLE*) theBLEObject
{
return ble;
}
-(void) connectionTimer:(NSTimer *)timer
{
if (ble.peripherals.count > 0)
{
[ble connectPeripheral:[ble.peripherals objectAtIndex:0]];
}
NSLog(#"connectionTimer"); // diag
}
// We call this when the view loads to try to connect to our bluetooth perepheral
//
- (void) scanForPeripherals
{
if (ble.activePeripheral)
if(ble.activePeripheral.state == CBPeripheralStateConnected)
{
statusLabel.text = #"Disconnectng from peripheral...";
[[ble CM] cancelPeripheralConnection:[ble activePeripheral]];
return;
}
if (ble.peripherals)
ble.peripherals = nil;
NSLog(#"scanning...");
statusLabel.text = #"Scanning for peripherals...";
[ble findBLEPeripherals:2];
[NSTimer scheduledTimerWithTimeInterval:(float)2.0 target:self selector:#selector(connectionTimer:) userInfo:nil repeats:NO];
//[indConnecting startAnimating];
}
- (IBAction)connect:(id)sender {
[self scanForPeripherals];
}
///////////////////////////////////////////////////////////
#pragma mark - BLE delegate
///////////////////////////////////////////////////////////
NSTimer *rssiTimer;
// When Connected, this will be called
-(void) bleDidConnect
{
NSLog(#"->Connected");
statusLabel.text = #"Connected!";
connectionStatus = #"Connected!";
// Schedule to read RSSI every 1 sec.
rssiTimer = [NSTimer scheduledTimerWithTimeInterval:(float)1.0 target:self selector:#selector(readRSSITimer:) userInfo:nil repeats:YES];
}
// When RSSI is changed, this will be called
-(void) bleDidUpdateRSSI:(NSNumber *) rssi
{
// Append the rssi value to our status label
//
NSString *temp = [NSString stringWithFormat:#"%# (%#)", connectionStatus, rssi];
statusLabel.text = temp;
}
-(void) readRSSITimer:(NSTimer *)timer
{
[ble readRSSI];
}
// When data is comming, this will be called
-(void) bleDidReceiveData:(unsigned char *)data length:(int)length
{
NSData *d = [NSData dataWithBytes:data length:length];
_myData = [NSData dataWithBytes:data length:length];
NSString *s = [[NSString alloc] initWithData:d encoding:NSUTF8StringEncoding];
NSLog(#"Datos en String %#",s);
//_datosdelegate = self;
//Is anyone listening
if([delegate respondsToSelector:#selector(actualizaDatos:)])
{
//send the delegate function with the amount entered by the user
[delegate actualizaDatos:_myData];
NSLog(#"Entro delegado");
}
}
- (void)bleDidDisconnect
{
NSLog(#"->Disconnected");
connectionStatus = #"Disconnected!";
statusLabel.text = #"Disconnected!";
[rssiTimer invalidate];
}
#end
sevenSegmentsViewController.h
#import <UIKit/UIKit.h>
#import "BLEViewController.h"
#import "BLE.h"
#interface sevenSegmentsViewController : UIViewController<EnviarDatos>{
UIImage *unoON;
UIImage *dosON;
UIImage *tresON;
UIImage *cuatroON;
UIImage *cincoON;
UIImage *seisON;
UIImage *sieteON;
UIImage *unoOFF;
UIImage *dosOFF;
UIImage *tresOFF;
UIImage *cuatroOFF;
UIImage *cincoOFF;
UIImage *seisOFF;
UIImage *sieteOFF;
}
#property (strong, nonatomic) IBOutlet UIImageView *uno;
#property (strong, nonatomic) IBOutlet UIImageView *dos;
#property (strong, nonatomic) IBOutlet UIImageView *tres;
#property (strong, nonatomic) IBOutlet UIImageView *cuatro;
#property (strong, nonatomic) IBOutlet UIImageView *cinco;
#property (strong, nonatomic) IBOutlet UIImageView *seis;
#property (strong, nonatomic) IBOutlet UIImageView *siete;
#end
sevenSegmentsViewController.m
//
// sevenSegmentsViewController.m
// iShield
//
// Created by Victor CarreƱo on 29/03/14.
// Copyright (c) 2014 RedBearLab. All rights reserved.
//
#import "sevenSegmentsViewController.h"
#interface sevenSegmentsViewController ()
#end
#implementation sevenSegmentsViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
unoOFF = [UIImage imageNamed:#"7segnh.png"];
dosOFF = [UIImage imageNamed:#"7segnv.png"];
tresOFF = [UIImage imageNamed:#"7segnv.png"];
cuatroOFF =[UIImage imageNamed:#"7segnh.png"];
cincoOFF = [UIImage imageNamed:#"7segnh.png"];
seisOFF = [UIImage imageNamed:#"7segnv.png"];
sieteOFF = [UIImage imageNamed:#"7segnh.png"];
unoON = [UIImage imageNamed:#"7segvh.png"];
dosON = [UIImage imageNamed:#"7segvv.png"];
tresON = [UIImage imageNamed:#"7segvv.png"];
cuatroON =[UIImage imageNamed:#"7segvh.png"];
cincoON = [UIImage imageNamed:#"7segvh.png"];
seisON = [UIImage imageNamed:#"7segvv.png"];
sieteON = [UIImage imageNamed:#"7segvh.png"];
_uno = [[UIImageView alloc]initWithImage:unoOFF];
_dos = [[UIImageView alloc]initWithImage:dosOFF];
_tres = [[UIImageView alloc]initWithImage:tresOFF];
_cuatro = [[UIImageView alloc]initWithImage:cuatroOFF];
_cinco = [[UIImageView alloc]initWithImage:cincoOFF];
_seis = [[UIImageView alloc]initWithImage:seisOFF];
_siete = [[UIImageView alloc]initWithImage:sieteOFF];
//BLEViewController *myBLE = [[BLEViewController alloc]init];
//BLE *myBLE = [BLEViewController theBLEObject];
//NSLog(#"%#", myBLE.myData);
BLEViewController *myBLE = [[BLEViewController alloc]init];
myBLE.delegate = self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
#pragma mark Delegado de Actualizar datos
-(void) actualizaDatos :(NSData *)myData{
NSLog(#"Datos recividos");
NSLog(#"Imprimio mi data con exitos %#", myData);
}
#end
In a nutshell, your BLEViewController is setting its delegate property to "self" when I think you want it to get set to an instance of "sevenSegmentsViewController". As a result the "if([delegate respondsToSelector:..." test is failing and you are never hitting the call to actualizaDatos. If you are using protocols correctly, you don't really need to test for "respondsToSelector" because by definition, the delegate must support the protocol.
The compiler and IDE are not showing you the error because you declared the property of the BLEViewController as just type "id" instead of
id<EnviarDatos>
If you fix the property declaration to say that your delegate must support the right protocol, you'll immediately see the errors highlighted.

moving text from bottom to top like marquee style in iOS application using textView

Moving text like marquee style from bottom to top in iOS application. i have tried this long time using google search but i could not get perfect answer for this question please provide any code for this question. i an new to iOS application.
Try this
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
NSTimer *timer;
UILabel *label ;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
timer =[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:#selector(scrollText:) userInfo:nil repeats:YES];
label = [[UILabel alloc] initWithFrame:CGRectMake(20, 50, 250, 20)];
label.text =#"This is a string to be scroll";
[self.view addSubview:label];
}
-(void)scrollText:(id)parameter{
if (label.frame.origin.y <= 50) {
[label setFrame:CGRectMake(label.frame.origin.x, 400, label.frame.size.width, label.frame.size.height)];
}
else
[label setFrame:CGRectMake(label.frame.origin.x, label.frame.origin.y-5, label.frame.size.width, label.frame.size.height)];
}
#end
You can find the same implementation in the below link. It's really awesome place for COCOA CONTROL.
COCOA CONTROLS
Check this answer.
.h
NSTimer *timer;
float timeDuration;
.m
-(void)viewDidLoad {
[super viewDidLoad];
timeDuration=1.0f;
timer = [NSTimer scheduledTimerWithTimeInterval:timeDuration target:self selector:#selector(marqueeAnimation) userInfo:nil repeats:YES];
}
-(void)marqueeAnimation{
UIImageView *imgView=[[UIImageView alloc]initWithFrame:CGRectMake(100, -100, 100, 100)];
[imgView setImage:[UIImage imageNamed:#"root.PNG"]];
[self.view addSubview:imgView];
NSString *keyPath = #"transform.translation.y";
CAKeyframeAnimation *translation = [CAKeyframeAnimation animationWithKeyPath:keyPath];
translation.duration = timeDuration;
translation.autoreverses = NO;
NSMutableArray *values = [[NSMutableArray alloc] init];
[values addObject:[NSNumber numberWithFloat:0.0f]];
CGFloat height = [[UIScreen mainScreen] applicationFrame].size.height;
[values addObject:[NSNumber numberWithFloat:height]];
translation.values = values;
NSMutableArray *timingFunctions = [[NSMutableArray alloc] init];
[timingFunctions addObject:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
translation.timingFunctions = timingFunctions;
[imgView.layer addAnimation:translation forKey:keyPath];
}
Try this. This works. Try this in a sample app and then include it in your app.
#import "ViewController.h"
#interface ViewController ()
#property(nonatomic, retain) NSTimer *timer;
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[_txtView setText:#"hi..."];
_timer = [NSTimer scheduledTimerWithTimeInterval:0.01f target:self selector:#selector(marqueeScroll) userInfo:nil repeats:YES];
}
-(void) marqueeScroll
{
[_txtView setFrame:CGRectMake(_txtView.frame.origin.x, _txtView.frame.origin.y-1.0, _txtView.frame.size.width, _txtView.frame.size.height)];
CGRect screen = [[UIScreen mainScreen] bounds];
if(_txtView.frame.origin.y <= 0 )
{
[_txtView setFrame:CGRectMake(_txtView.frame.origin.x, screen.size.height,_txtView.frame.size.width, _txtView.frame.size.height)] ;
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Let me know if there are any errors.

UIButton action is not firing from my own class

I have a class which is generating UIButtons dynamically and I want to keep the selector action in the same class as method to make it generic. When I click on the button it crashing. Bellow is my code
RB_RadioButton.h
#import <Foundation/Foundation.h>
#interface RB_RadioButton : NSObject {
NSMutableArray *options;
}
-(id)initWithOptions:(NSArray *)options;
-(void)renderRadioButtons:(UIView *)view initialXPos:(int)initialXPos initialYPos:(int)initialYPos height:(int)height width:(int)width spacing:(int)spacing;
#end
RB_RadioButton.m
#import "RB_RadioButton.h"
#implementation RB_RadioButton {
NSMutableArray *buttonArray;
}
-(id)initWithOptions:(NSArray *)optionsArray {
if(self = [super init]){
options = [[NSMutableArray alloc]initWithArray:optionsArray];
}
return self;
}
-(void)renderRadioButtons:(UIView *)view initialXPos:(int)initialXPos initialYPos:(int)initialYPos height:(int)height width:(int)width spacing:(int)spacing {
buttonArray = [[NSMutableArray alloc]init];
int xpos = initialXPos, ypos = initialYPos;
for (int i = 0; i < options.count; i++) {
UIButton *radio = [[UIButton alloc]initWithFrame:CGRectMake(xpos, ypos, height, width)];
radio.backgroundColor = [UIColor grayColor];
[radio setTag:i];
[radio addTarget:[RB_RadioButton class] action:#selector(actionTap) forControlEvents:UIControlEventTouchUpInside];
UILabel *l = [[UILabel alloc]initWithFrame:CGRectMake(xpos+30, ypos, height, width)];
l.text = [options objectAtIndex:i];
ypos = ypos + height + spacing;
[view addSubview:l];
[view addSubview:radio];
}
}
-(void)actionTap{
NSLog(#"lll");
}
#end
viewController.m
#import "RB_ViewController.h"
#import "RB_RadioButton.h"
#interface RB_ViewController ()
#end
#implementation RB_ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSArray *arr = [[NSArray alloc]initWithObjects:#"a",#"b",#"c", nil];
RB_RadioButton *rd = [[RB_RadioButton alloc]initWithOptions:arr];
[rd renderRadioButtons:self.view initialXPos:20 initialYPos:20 height:20 width:20 spacing:10];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Above code is crashing without any message in debug console.
Please help !
Thanks
Whenever you write this line of code it'l take class method so define actionTap as class method then it'l works like below.
[radio addTarget:[RB_RadioButton class] action:#selector(actionTap) forControlEvents:UIControlEventTouchUpInside];
+(void)actionTap{
NSLog(#"lll");
}
What is that:
[radio addTarget:[RB_RadioButton class] action:#selector(actionTap) forControlEvents:UIControlEventTouchUpInside];
actionTap is normal method which requires self pointer but you are trying to invoke it on Class object!
This line should look like this:
[radio addTarget: self action:#selector(actionTap) forControlEvents:UIControlEventTouchUpInside];
To make it work you have to fix also memory management. Controller should remember your RB_RadioButton object as a filed and release it in dealloc method.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSArray *arr = [NSArray arrayWithObjects: #"a",#"b",#"c", nil]; // here also you had a memory leak
rd = [[RB_RadioButton alloc]initWithOptions:arr]; // rd is object field
[rd renderRadioButtons:self.view initialXPos:20 initialYPos:20 height:20 width:20 spacing:10];
}
- (void)dealloc {
[rd release];
[super dealloc];
}

Memory getting increased everytime I am going into this view and I cant use arc in this code

Every time I am entering the same view memory is increasing. Even I am releasing nothing is happening and I can't use ARC due to older app issue. Don't know how to solve this issue.
#import <UIKit/UIKit.h>
#import "CareServices.h"
#interface AttachedImage : UIViewController<ServerConnectionDelegate,UIScrollViewDelegate>
{
IBOutlet UIImageView *imageView;
CareServices *careServices;
UIScrollView *_scrollView;
UIView *activityView;
UIActivityIndicatorView *_activity;
}
#property (nonatomic,retain)UIImageView *imageView;
#end
#import "AttachedImage.h"
#import"XMLParserForOtherAttachments.h"
#import "ColorSchemes.h"
#implementation AttachedImage
#synthesize imageView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
activityView = [[UIView alloc]initWithFrame:CGRectMake(self.view.frame.size.width/2.5,self.view.frame.size.height/2.5, 60, 60)];
activityView.backgroundColor = [UIColor clearColor];
[self.view addSubview:activityView];
UIImageView *activityImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, activityView.frame.size.width, activityView.frame.size.height)];
activityImageView.image = [UIImage imageNamed:#"indicatorImage.jpeg"];
[activityView addSubview:activityImageView];
[activityImageView release];
_activity = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[_activity setFrame:CGRectMake(activityView.frame.size.width/5.8, activityView.frame.size.height/5.3, 40, 40)];
[activityView addSubview:_activity];
[_activity startAnimating];
[_activity release];
careServices = [CareServices currentInstance];
careServices.delegate = self;
[[NSURLCache sharedURLCache] removeAllCachedResponses];
[super viewDidLoad];
self.navigationItem.title = #"Attachment View";
// self.view.backgroundColor = [ColorSchemes sharedInstance].primaryColor1;
self.view.backgroundColor = [UIColor blackColor];;
// Do any additional setup after loading the view from its nib.
}
-(void)viewDidAppear:(BOOL)animated {
NSString *senderTagStr;
NSUserDefaults *senderD = [NSUserDefaults standardUserDefaults];
senderTagStr = [senderD valueForKey:#"sender tag"];
_scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
_scrollView.maximumZoomScale = 4.0;
_scrollView.minimumZoomScale = 1.0;
_scrollView.delegate = self;
_scrollView.contentSize = CGSizeMake(400, 500);
if (careServices.loginMode == ELoginModeDemo) {
if ([senderTagStr isEqualToString:#"0"]) {
imageView.image = [UIImage imageNamed:#"R1.bmp"];
}
else {
imageView.image = [UIImage imageNamed:#"8.jpg"];
}
}
else {
NSString *str = [NSString stringWithString:[XMLParserForOtherAttachments sharedManager].fileURlStr];
NSString *trimmedStr = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSData *imgData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:trimmedStr]];
UIImage *myImage = [UIImage imageWithData:imgData];
imageView.image = myImage;
[imgData release];
}
[_scrollView addSubview:imageView];
[self.view addSubview:_scrollView];
[_activity stopAnimating];
[activityView removeFromSuperview];
}
- (void)viewDidUnload {
[[NSURLCache sharedURLCache] removeAllCachedResponses];
self.imageView = nil;
[super viewDidUnload];
}
- (void)dealloc{
[imageView release];
[super dealloc];
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return imageView;
}
#end
Locating the offending allocations/implementations is quite easy once you learn to use Heapshot Analysis.
Heapshot Analysis allows you to take snapshots during your execution in order to detect growths over a period of time, which you can of course associate with user actions in many cases. So you could for example push a view controller onto the navigation stack in iOS, then step back and easily determine what the growth was in doing so. Then navigate to the implementations which caused the growths.

Resources