I am working on adding text on image. I found that CLImageEditor tool is very good. but i only want to use add text tool with my own theme. so can i use that tool in my app. or any other tool that i can use in my app.
You could do this for every tool.
CLImageToolInfo *tool = [editor.toolInfo subToolInfoWithToolName:#"CLToneCurveTool" recursive:NO];
tool.available = NO; // if available is set to NO, it is removed from the menu view.
No, you cant directly open a submenu. May be raise an issue to them at https://github.com/yackle/CLImageEditor/issues
If you want to show only few options or you want to customize item location you can do this way:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
CLImageEditor *editor = [[CLImageEditor alloc] initWithImage:image];
editor.delegate = self;
CLImageToolInfo *tool1 = [editor.toolInfo subToolInfoWithToolName:#"CLAdjustmentTool" recursive:NO];
CLImageToolInfo *tool2 = [editor.toolInfo subToolInfoWithToolName:#"CLBlurTool" recursive:NO];
CLImageToolInfo *tool3 = [editor.toolInfo subToolInfoWithToolName:#"CLRotateTool" recursive:NO];
CLImageToolInfo *tool4 = [editor.toolInfo subToolInfoWithToolName:#"CLToneCurveTool" recursive:NO];
tool1.available = NO;
tool2.available = NO;
tool3.available = NO;
tool4.available = NO;
[picker pushViewController:editor animated:YES];
}
This is possible by tweeking the existing code as below:
//First disable all the tools like below but the one you need.
var tool = editor.toolInfo.subToolInfoWithToolName("CLRotateTool", recursive: false)
tool.available = false
//replace below 4 functions in CLImageEditorView Controller
- (void)setMenuView
{
CGFloat x = 0;
CGFloat W = 70;
CGFloat H = _menuView.height;
int toolCount = 0;
CGFloat padding = 0;
for(CLImageToolInfo *info in self.toolInfo.sortedSubtools){
if(info.available){
toolCount++;
}
}
CGFloat diff = _menuView.frame.size.width - toolCount * W;
if (0<diff && diff<2*W) {
padding = diff/(toolCount+1);
}
for(CLImageToolInfo *info in self.toolInfo.sortedSubtools){
if(!info.available){
continue;
}
CLToolbarMenuItem *view = [CLImageEditorTheme menuItemWithFrame:CGRectMake(x+padding, 0, W, H) target:self action:#selector(tappedMenuView:) toolInfo:info];
[_menuView addSubview:view];
x += W+padding;
[self tappedMenuView:view];
}
_menuView.contentSize = CGSizeMake(MAX(x, _menuView.frame.size.width+1), 0);
}
- (IBAction)pushedCancelBtn:(id)sender
{
_imageView.image = _originalImage;
[self resetImageViewFrame];
self.currentTool = nil;
[self pushedCloseBtn:nil];
}
- (IBAction)pushedDoneBtn:(id)sender
{
self.view.userInteractionEnabled = NO;
[self.currentTool executeWithCompletionBlock:^(UIImage *image, NSError *error, NSDictionary *userInfo) {
if(error){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
else if(image){
_originalImage = image;
_imageView.image = image;
[self resetImageViewFrame];
self.currentTool = nil;
}
self.view.userInteractionEnabled = YES;
[self pushedFinishBtn:nil];
}];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = self.toolInfo.title;
self.view.clipsToBounds = YES;
self.view.backgroundColor = self.theme.backgroundColor;
self.navigationController.view.backgroundColor = self.view.backgroundColor;
if([self respondsToSelector:#selector(automaticallyAdjustsScrollViewInsets)]){
self.automaticallyAdjustsScrollViewInsets = NO;
}
if([self.navigationController respondsToSelector:#selector(interactivePopGestureRecognizer)]){
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
[self initNavigationBar];
[self initMenuScrollView];
[self initImageScrollView];
if(_imageView==nil){
_imageView = [UIImageView new];
[_scrollView addSubview:_imageView];
[self refreshImageView];
}
[self setMenuView];
}
You can not open submenu directly.
I created a remover function for removing the subtools. Swift 4.2
private func removeTools(tools: [String]) {
tools.forEach {
guard let imageEditor = self.imageEditor else { return }
let tool = imageEditor.toolInfo.subToolInfo(withToolName: $0, recursive: false)
tool?.available = false
}
}
You can call like this;
removeTools(tools: ["CLFilterTool", "CLEffectTool"])
Related
My app runs perfectly on simulator.
But when I run it on device to test, the app crashed.
The displayed error :
"malloc: * error for object 0x17415d0c0: Invalid pointer dequeued from free list * set a breakpoint in malloc_error_break to debug";
And another error sometimes happens :
"Thread 6 com.apple.NSURLConnectionLoader: Program received signal: EXC_BAD_ACCESS"
This two errors are random, it happens after the app runs two or three minutes.
I searched Google and find some solution.
It says that set a breakpoint in malloc_error_break to debug, but this only work on simulator. Even I set the malloc_error_break, the app still crush and it does not display anything, I only can see that error message.
This is big project, I really do not know which part of the code cause the problem and which part of the code I need to post.
But I have doubt with one of the class, my 'SynchroningView'.
This view will be displayed if only my app make synchronisation with the server. It means this view is included in almost all the Viewcontroller in my project.
Here is my 'SynchroningView' class:
"SynchroningView.h"
#import <UIKit/UIKit.h>
#class SynchroningView;
#protocol SynchroningViewDelegate
#optional
- (void)SynchroningViewCancelButtonDidClicked:(SynchroningView *)synchroningView;
- (void)SynchroningViewStartTherapyButtonDidClicked:(SynchroningView *)synchroningView;
#end
#interface SynchroningView : UIView <DataManagerDelegate>
#property (nonatomic, assign) id<SynchroningViewDelegate>delegateCustom;
#property (nonatomic, retain) UIButton *containerButton;
#property (nonatomic, retain) Patient *singlePatient;
- (instancetype)initWithFrame:(CGRect)frame;
- (void)showInView:(UIView *)view;
- (void)dismissMenuPopover;
#end
SynchroningView.m
#import "SDDemoItemView.h"
#import "SDPieLoopProgressView.h"
#define Directory_Document [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
#define FileName_Image_SynchroningView_BackGroundImageName #"SynchroningView_BackGroundImage"
#define FilePath_Image_SynchroningView_BackGroundImageName [Directory_Document stringByAppendingPathComponent:FileName_Image_SynchroningView_BackGroundImageName]
#interface SynchroningView ()
#property (nonatomic, strong) DataManager* dataManager;
#property (nonatomic, retain) UILabel* messageLabel;
#property (nonatomic, retain) UIButton* CancelButton;
#property (nonatomic, retain) CoolButton* ConfirmButton;
#property (nonatomic, retain) CoolButton* startTherapyButton;
#property (nonatomic, strong) SDDemoItemView* demoProgressView;
#end
#interface SynchroningView ()
{
BOOL _blinking;
NSTimer *timer;
}
#end
#implementation SynchroningView
-(void)dealloc
{
}
//get the background Image, make it blur and save it. In this way I do not have to use Blur function everytim, I use the blured image directly
- (UIImage *)getBackGroundImage
{
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:FilePath_Image_SynchroningView_BackGroundImageName]) {
return [UIImage imageWithContentsOfFile:FilePath_Image_SynchroningView_BackGroundImageName];
}
else{
UIImage *backImage = [UIImage imageWithContentsOfFile:kBackgroundImagePath];
backImage = [backImage blurWithFloat:20.0f];
NSData * binaryImageData = UIImagePNGRepresentation(backImage);
if ([binaryImageData writeToFile:FilePath_Image_SynchroningView_BackGroundImageName atomically:YES]) {
return backImage;
}
}
return [UIImage imageWithContentsOfFile:kBackgroundImagePath];
}
-(instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
_blinking = NO;
self.dataManager = [[DataManager alloc] init];
self.dataManager.DelegateCustom = self;
self.backgroundColor = [UIColor clearColor];
self.containerButton = [[UIButton alloc] init];
[self.containerButton setBackgroundColor:RGBA_Custom(0, 0, 0, 0.6f)];
[self.containerButton setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin];
UIView *shadowView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
[self addSubview:shadowView];
shadowView.backgroundColor = RGBA_Custom(230, 249, 251, 0.96f);
// shadowView.layer.borderWidth = 2*IPAD;
// shadowView.layer.borderColor = [RGBA_Custom(199, 199, 199, 1.0f) CGColor];
shadowView.layer.shadowColor = [UIColor blackColor].CGColor;
shadowView.layer.shadowOpacity = 0.4;
shadowView.layer.shadowRadius = 4*IPAD;
shadowView.layer.shadowOffset = CGSizeMake(4.0f*IPAD, 4.0f*IPAD);
shadowView.layer.cornerRadius = 6*IPAD;
shadowView.userInteractionEnabled = NO;
UIImageView *backGround = [[UIImageView alloc] initWithImage:[self getBackGroundImage]];
backGround.frame = CGRectMake(0, 0, shadowView.frame.size.width, shadowView.frame.size.height);
backGround.backgroundColor = [UIColor clearColor];
[shadowView addSubview:backGround];
backGround.layer.cornerRadius = shadowView.layer.cornerRadius;
backGround.layer.masksToBounds = YES;
ImageWIDTH_ = self.frame.size.height*0.3;
self.demoProgressView =[SDDemoItemView demoItemViewWithClass:[SDPieLoopProgressView class]];
self.demoProgressView.frame = CGRectMake((self.frame.size.width - ImageWIDTH_)/2,
kFromLeft,
ImageWIDTH_,
ImageWIDTH_);
[self addSubview:self.demoProgressView];
self.messageLabel = [[UILabel alloc] initWithFrame:CGRectMake(kFromLeft,
self.demoProgressView.frame.origin.y + self.demoProgressView.frame.size.height + kFromLeft,
self.frame.size.width - kFromLeft*2,
self.frame.size.height - (self.demoProgressView.frame.origin.y + self.demoProgressView.frame.size.height + kFromLeft*2))];
self.messageLabel.backgroundColor = [UIColor clearColor];
self.messageLabel.textColor = [UIColor blackColor];
self.messageLabel.textAlignment = NSTextAlignmentCenter;
self.messageLabel.numberOfLines = 0;
self.messageLabel.lineBreakMode = NSLineBreakByWordWrapping;
self.messageLabel.font = [UIFont boldSystemFontOfSize:kIPAD ? 20:12];
self.messageLabel.text = #"";
self.messageLabel.adjustsFontSizeToFitWidth = YES;
[self addSubview:self.messageLabel];
CGFloat BtnHeight = kIPAD ? 40 : 30;
self.CancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.CancelButton.frame = CGRectMake(self.frame.size.width - kFromLeft*0.5 - BtnHeight,
kFromLeft*0.5,
BtnHeight,
BtnHeight);
self.CancelButton.backgroundColor = [UIColor clearColor];
[self.CancelButton setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"utilities_close" ofType:#"png"]] forState:UIControlStateNormal];
[self.CancelButton addTarget:self action:#selector(pressCancelButton:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.CancelButton];
BtnHeight = kIPAD ? 70 : 50;
CGFloat BtnWidth = self.frame.size.width/4;
NSString* ConfirmButtonStr = NSLocalizedString(#"Confirm", nil);
ExpectedSize = [ConfirmButtonStr sizeWithFont:self.messageLabel.font constrainedToSize:CGSizeMake(VIEW_WIDTH, BtnHeight) lineBreakMode:NSLineBreakByWordWrapping];
ExpectedSize = CGSizeMake(ExpectedSize.width + 30*IPAD, ExpectedSize.height);
self.ConfirmButton = [CoolButton buttonWithType:UIButtonTypeCustom];
self.ConfirmButton.frame = CGRectMake((self.frame.size.width - ExpectedSize.width)/2,
self.frame.size.height - BtnHeight - kFromLeft,
ExpectedSize.width,
BtnHeight);
self.ConfirmButton.titleLabel.font = self.messageLabel.font;
[self.ConfirmButton setTitle:ConfirmButtonStr forState:UIControlStateNormal];
[self.ConfirmButton addTarget:self action:#selector(pressConfirmButton:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.ConfirmButton];
BtnWidth = self.frame.size.width*0.6;
NSString* startTherapyButtonStr = NSLocalizedString(#"StartTerapia", nil);
ExpectedSize = [startTherapyButtonStr sizeWithFont:self.messageLabel.font constrainedToSize:CGSizeMake(VIEW_WIDTH, BtnHeight) lineBreakMode:NSLineBreakByWordWrapping];
ExpectedSize = CGSizeMake(ExpectedSize.width + 30*IPAD, ExpectedSize.height);
self.startTherapyButton = [CoolButton buttonWithType:UIButtonTypeCustom];
self.startTherapyButton.frame = CGRectMake((self.frame.size.width - ExpectedSize.width)/2,
self.ConfirmButton.frame.origin.y,
ExpectedSize.width,
self.ConfirmButton.frame.size.height);
self.startTherapyButton.titleLabel.font = self.messageLabel.font;
[self.startTherapyButton setTitle:startTherapyButtonStr forState:UIControlStateNormal];
[self.startTherapyButton addTarget:self action:#selector(startTherapyButtonDidClicked:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.startTherapyButton];
self.CancelButton.alpha = 0.0;
self.ConfirmButton.alpha = 0.0;
self.startTherapyButton.alpha = 0.0;
if (self.dataManager.firstSynchronizationAgain == 1 && [AccessedInfo getAccessedInfo]) {
UILabel *alertInfoLabel = [[UILabel alloc] initWithFrame:CGRectMake(kFromLeft,
0,
self.frame.size.width - kFromLeft*2,
VIEW_HEIGHT)];
alertInfoLabel.backgroundColor = [UIColor clearColor];
alertInfoLabel.textColor = COLOR_CIRCLE;
alertInfoLabel.textAlignment = NSTextAlignmentCenter;
alertInfoLabel.numberOfLines = 0;
alertInfoLabel.lineBreakMode = NSLineBreakByWordWrapping;
alertInfoLabel.font = [UIFont systemFontOfSize:self.startTherapyButton.titleLabel.font.pointSize-2];
alertInfoLabel.text = NSLocalizedString(#"SynchronizingNew", nil);
ExpectedSize = [alertInfoLabel.text sizeWithFont:alertInfoLabel.font constrainedToSize:alertInfoLabel.frame.size lineBreakMode:NSLineBreakByWordWrapping];
alertInfoLabel.frame = CGRectMake(alertInfoLabel.frame.origin.x,
self.startTherapyButton.frame.origin.y - ExpectedSize.height - IPAD*2,
alertInfoLabel.frame.size.width,
ExpectedSize.height);
[self addSubview:alertInfoLabel];
}
[self.containerButton addSubview:self];
}
return self;
}
//show the synchronization result message
- (void)setMessageLabelString:(NSString *)labelName
{
self.messageLabel.text = labelName;
ExpectedSize = [labelName sizeWithFont:self.messageLabel.font constrainedToSize:CGSizeMake(self.messageLabel.frame.size.width, VIEW_HEIGHT) lineBreakMode:NSLineBreakByWordWrapping];
self.messageLabel.frame = CGRectMake(self.messageLabel.frame.origin.x,
self.messageLabel.frame.origin.y,
self.messageLabel.frame.size.width,
ExpectedSize.height);
timer = [NSTimer scheduledTimerWithTimeInterval:0.8 target:self selector:#selector(MessageLabelBlinking) userInfo:nil repeats:YES];
// self.messageLabel.adjustsFontSizeToFitWidth = YES;
}
- (void)MessageLabelBlinking
{
if (_blinking) {
NSString *threeDot = #".....";
if ([self.messageLabel.text rangeOfString:threeDot].location == NSNotFound) {
self.messageLabel.text = [self.messageLabel.text stringByAppendingString:#"."];
}
else{
self.messageLabel.text = [self.messageLabel.text stringByReplacingOccurrencesOfString:threeDot withString:#""];
}
}
else{
[timer invalidate];
timer = nil;
}
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
//init the data processing block
- (void)initCustomOtherParameters
{
self.dataManager.DelegateCustom = self;
self.dataManager.blockProcessingData = ^(float allCommand, float restCommand){
if (allCommand == 0) {
[[SingletonOperationQueue mainQueue] addOperationWithBlock:^{
self.demoProgressView.progressView.progress = 1;
NSString *messageStr = [NSLocalizedString(#"SuccessfulSynchronized", nil) stringByAppendingFormat:#"\n%#", NSLocalizedString(#"EmptyTherapy", nil)];
[self setMessageLabelString:messageStr];
_blinking = NO;
self.CancelButton.alpha = 1.0;
}];
}
else{
float percenAger = (restCommand/allCommand);
percenAger = 1 - percenAger;
[[SingletonOperationQueue mainQueue] addOperationWithBlock:^{
self.demoProgressView.progressView.progress = percenAger;
if (restCommand == 0) {
[self downloadZipFile];
}
}];
}
};
[Patient RemovePatient];
[self.singlePatient SavePatient];
}
- (void)showInView:(UIView *)view
{
self.transform = CGAffineTransformScale(self.transform, 0.8, 0.8);
self.containerButton.alpha = 0.0f;
self.containerButton.frame = view.bounds;
[view addSubview:self.containerButton];
[UIView animateWithDuration:0.15 animations:^{
self.containerButton.alpha = 1.0f;
self.transform = CGAffineTransformScale(self.transform, 1.4, 1.4);
}completion:^(BOOL finished) {
if (finished) {
[UIView animateWithDuration:0.20 animations:^{
self.transform = CGAffineTransformIdentity;
}];
[self sendConnectionTestRequest];
}
else{
self.transform = CGAffineTransformIdentity;
[self sendConnectionTestRequest];
}
}];
}
- (void)dismissMenuPopover
{
[self hide];
}
- (void)hide
{
[UIView animateWithDuration:0.25 animations:^{
self.transform = CGAffineTransformScale(self.transform, 0.8, 0.8);
self.containerButton.alpha = 0.0f;
}completion:^(BOOL finished) {
if (finished) {
[self.containerButton removeFromSuperview];
}
}];
}
- (void)pressCancelButton:(UIButton *)button
{
[self.dataManager CommunicationCancel];
[self.delegateCustom SynchroningViewCancelButtonDidClicked:self];
}
- (void)startTherapyButtonDidClicked:(UIButton *)button
{
[self.delegateCustom SynchroningViewStartTherapyButtonDidClicked:self];
}
- (void)pressConfirmButton:(UIButton *)button
{
[UIView animateWithDuration:0.25 animations:^{
self.CancelButton.alpha = 0.0;
self.ConfirmButton.alpha = 0.0;
}];
[self sendRegistrationRequestConfirm:YES];
}
#pragma mark - Communication
- (void)sendConnectionTestRequest
{
[self initCustomOtherParameters];
_blinking = YES;
[self setMessageLabelString:NSLocalizedString(#"StartRegistration", nil)];
[self.dataManager sendRequestCommand:kConnectionTest];
}
- (void)sendRegistrationRequestConfirm:(BOOL)Confirm
{
[self setMessageLabelString:NSLocalizedString(#"StartRegistration", nil)];
NSString *registrationResult = [self.dataManager RegisterTheUSER_Confirm:Confirm];
[self processLogInResult:registrationResult];
}
- (void)processLogInResult:(NSString *)logInResult
{
if ([logInResult isEqual:#"1"]) {
if ([self.dataManager DataInitialization]) {
[self.dataManager DataInitializationForFakeUser];
[self.singlePatient SavePatient];
[self startTherapyButtonDidClicked:nil];
}
}
else if ([logInResult isEqual:#"2"]) {
if ([self.dataManager DataInitialization]) {
self.singlePatient.record7_AuthenticatedUser = YES;
[self.singlePatient SavePatient];
[self.dataManager sendRequestCommand:kNewDataAvailable];
};
}
else if ([logInResult intValue] == DEVICE_NOT_REGISTERED){
logInResult = NSLocalizedString(#"105", nil);
_blinking = NO;
[self setMessageLabelString:logInResult];
[UIView animateWithDuration:0.25 animations:^{
self.CancelButton.alpha = 1.0;
self.ConfirmButton.alpha = 1.0;
}];
}
else if ([logInResult isEqualToString:kNO]){
_blinking = NO;
[self setMessageLabelString:#"Cannot find the Error "];
[UIView animateWithDuration:0.25 animations:^{
self.CancelButton.alpha = 1.0;
}];
}
else{
_blinking = NO;
[self setMessageLabelString:logInResult];
[UIView animateWithDuration:0.25 animations:^{
self.CancelButton.alpha = 1.0;
}];
}
}
- (void)downloadZipFile
{
self.demoProgressView.progressView.progress = 1.0;
sleep(0.4);
[self setMessageLabelString:NSLocalizedString(#"Loading Data", nil)];
self.demoProgressView.progressView.progress = 0.0;
self.dataManager.blockProcessingDataPercentAge = ^(float percentAge, NSString *fileName){
if ([fileName isEqualToString:kaderenzainfo]) {
[[SingletonOperationQueue mainQueue] addOperationWithBlock:^{
self.demoProgressView.progressView.progress = percentAge;
NSLog(#"%f", percentAge);
if (percentAge == 0.5) {
sleep(0.4);
NSString *aderenzainfoFilePath = [[NSUserDefaults standardUserDefaults] objectForKey:kaccertamentiinfo];
[self.dataManager downloadZipFile:aderenzainfoFilePath fileName:kaccertamentiinfo];
}
}];
}
else if ([fileName isEqualToString:kaccertamentiinfo]){
[[SingletonOperationQueue mainQueue] addOperationWithBlock:^{
self.demoProgressView.progressView.progress = 0.5 + percentAge;
if (0.5 + percentAge >= 1.0) {
_blinking = NO;
self.CancelButton.alpha = 1.0;
if ([Patient getPatient].record_patientStatus == PatientStatusSuspendedType) {
[self setMessageLabelString:NSLocalizedString(#"SuspendedPatient", nil)];
}
else if ([Patient getPatient].record_patientStatus == PatientStatusDeletedType){
[self setMessageLabelString:NSLocalizedString(#"DeletedPatient", nil)];
}
else if ([Patient getPatient].record_patientStatus == PatientStatusActiveType){
[self setMessageLabelString:NSLocalizedString(#"SuccessfulSynchronized", nil)];
self.startTherapyButton.alpha = 1.0;
}
}
}];
}
};
NSString *aderenzainfoFilePath = [[NSUserDefaults standardUserDefaults] objectForKey:kaderenzainfo];
[self.dataManager downloadZipFile:aderenzainfoFilePath fileName:kaderenzainfo];
}
#pragma mark - DataManagerDelegate
- (void)CommunicationConnectionTest:(BOOL)connected
{
if (connected) {
[self sendRegistrationRequestConfirm:NO];
}
else{
[self setMessageLabelString:NSLocalizedString(#"connectionTestFail", nil)];
[UIView animateWithDuration:0.25 animations:^{
self.CancelButton.alpha = 1.0;
}];
_blinking = NO;
}
}
- (void)CommunicationSendRequestCommandName:(NSString *)commandName
{
if ([commandName isEqualToString:kNewDataAvailable]) {
[self setMessageLabelString:NSLocalizedString(#"Synchronizing", nil)];
}
}
- (void)CommunicationReceiveResponseWithOKCommandName:(NSString *)commandName
{
}
- (void)CommunicationReceiveResponseWithRequestError:(NSString *)commandName
{
[self setMessageLabelString:NSLocalizedString(#"NetworkConnectionError", nil)];
_blinking = NO;
[UIView animateWithDuration:0.25 animations:^{
self.CancelButton.alpha = 1.0;
}];
}
- (void)CommunicationReceiveResponseCommandName:(NSString *)commandName WithErrorCode:(int)errorCode withErrorDescription:(NSString *)errorDescription
{
[self setMessageLabelString:NSLocalizedString(#"NewDataAvaiableErrorCode", nil)];
_blinking = NO;
[UIView animateWithDuration:0.25 animations:^{
self.CancelButton.alpha = 1.0;
}];
}
-(void)CommunicationZipFileFailDownload
{
[self setMessageLabelString:NSLocalizedString(#"ZipFileDownloadFail", nil)];
_blinking = NO;
[UIView animateWithDuration:0.25 animations:^{
self.CancelButton.alpha = 1.0;
}];
}
-(void)CommunicationZipFileIsNotReadAble
{
[self setMessageLabelString:NSLocalizedString(#"ZipFileUnzippedFail", nil)];
_blinking = NO;
[UIView animateWithDuration:0.25 animations:^{
self.CancelButton.alpha = 1.0;
}];
}
#end
I solved it finally
Inside my Encryption and Decryption function, I have this:
Byte *buffer = (Byte*)malloc(asciiDataLength);
After I processed with buffer, I convert it to NSData:
NSData *plainData = [NSData dataWithBytesNoCopy:buffer length:asciiDataLength freeWhenDone:YES];
This code causes my app crushes continuously, I changed it to
NSData *plainData = [NSData dataWithBytes:buffer length:asciiDataLength];
free(buffer);
Then my app never crush again.
So, I have to free the Byte by myself, ARC will not free it for me.
Simulator's memory = Pc's RAM i.e 4 or 6 gb etc.
and device have only 1 gb maximum. In Xcode while you run the app, you need to click on Debug Navigator, and then click on Memory, it will display the memory consumption of your app.
To see the Leakage of Memory in your code - you have to go to memory tools, like Instruments.
First off: My project is ARC enabled and I'm using storyboard.
I have a view controller that pushes a segue (modal),
[self performSegueWithIdentifier: #"goInitialSettings" sender: self];
there i'm setting some parameters and store them. When the parameters are stored (true a button tap), the app should return to the original viewcontroller.
This i am doing with this command:
[self.presentingViewController dismissViewControllerAnimated:NO completion:^{}];
I'm noticing that the viewcontroller that i dismiss, never deallocs. How does this come?
I'm adding the code of the 'presented viewcontroller' below:
#interface CenterChoiceController ()
{
UIView* _titleBackground;
UILabel* _lblTitle;
UIButton* _btnGaVerder;
UIPickerView* _myPickerView;
NSArray* _centers;
UILabel* _adresLine;
UILabel* _cityLine;
MKPointAnnotation* _point;
MKMapView* _mapView;
UIActivityIndicatorView* _indicator;
UIAlertView* _alert;
GCenter* _center;
DataManager* _dm;
}
#end
#implementation CenterChoiceController
-(void)dealloc
{
NSLog(#"Centerchoice deallocs");
_titleBackground = nil;
_lblTitle = nil;
_btnGaVerder = nil;
_myPickerView = nil;
_point = nil;
_mapView = nil;
_indicator = nil;
_alert = nil;
_centers = nil;
_adresLine = nil;
_cityLine = nil;
_center = nil;
_dm = nil;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
_dm = [[DataManager alloc]init];
if([_dm hasConnectivity])
{
[_dm fetchCentersForController:self];
}
else
{
[self pushErrorMessage:NSLocalizedString(#"nointernetconnection", nil)];
}
CAGradientLayer *bgLayer = [BackgroundLayer blueGradient];
bgLayer.frame = self.view.bounds;
[self.view.layer insertSublayer:bgLayer atIndex:0];
_titleBackground = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
_titleBackground.backgroundColor = [GColor blueColor];
[self.view addSubview:_titleBackground];
_lblTitle = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width - 10, 44)];
_lblTitle.textAlignment = NSTextAlignmentRight;
_lblTitle.textColor = [GColor whiteColor];
_lblTitle.text = NSLocalizedString(#"bioscoopkeuze", nil);
[self.view addSubview:_lblTitle];
_btnGaVerder = [[UIButton alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height - 54, self.view.frame.size.width, 54)];
[_btnGaVerder setTitle:NSLocalizedString(#"gaverder", nil) forState:UIControlStateNormal];
_btnGaVerder.titleLabel.font = [_btnGaVerder.titleLabel.font fontWithSize:12];
_btnGaVerder.backgroundColor = [GColor blueColor];
[_btnGaVerder setTitleColor:[GColor whiteColor] forState:UIControlStateNormal];
[_btnGaVerder setShowsTouchWhenHighlighted:YES];
[_btnGaVerder addTarget:self action:#selector(gaVerder) forControlEvents:UIControlEventTouchUpInside];
_myPickerView = [[UIPickerView alloc]initWithFrame:CGRectMake(0, 44, self.view.frame.size.width, 200)];
}
-(void)showLoading
{
NSLog(#"shows loading");
_indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
CGPoint cntr = self.view.center;
_indicator.center = cntr;
[_indicator startAnimating];
[self.view addSubview:_indicator];
}
-(void)hideLoading
{
NSLog(#"hides loading");
[_indicator removeFromSuperview];
_indicator = nil;
}
-(void)pushData:(NSArray *)data
{
[self.view addSubview:_btnGaVerder];
[self.view addSubview:_myPickerView];
_centers = data;
_myPickerView.delegate = self;
_myPickerView.dataSource = self;
_dm = [[DataManager alloc]init];
GSettings* settings = [_dm loadSettings];
if(settings == nil)
{
settings = [[GSettings alloc]init];
settings.chosenCenter = [_centers objectAtIndex:0];
settings.loadedCenter = [_centers objectAtIndex:0];
_center = settings.chosenCenter;
settings.notificationsEnabled = YES;
[self changeAddressLines];
}
/*if(settings != nil)
{
GCenter* loaded = settings.loadedCenter;
int i = 0;
BOOL found = NO;
while(i < [_centers count] && !found)
{
GCenter* center = (GCenter*)[_centers objectAtIndex:i];
if(settings.loadedCenter.iD == center.iD)
{
_center = center;
settings.chosenCenter = center;
[_dm storeSettings:settings];
found = YES;
}
i++;
}
//[self.myPickerView selectRow:i-1 inComponent:0 animated:NO];
loaded = nil;
[self changeAddressLines];
}
*/
}
-(void) pushErrorMessage: (NSString*) errorMessage
{
_alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(#"fout", nil) message:errorMessage delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil];
_alert.delegate = self;
[_alert show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 0)
{
if(self.navigationController != nil)
{
[self.navigationController popViewControllerAnimated:YES];
}
else
{
//[self initializeData];
}
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)viewWillDisappear:(BOOL)animated
{
[_dm cancelCenterRequest];
/*if(self.tabBarController != nil)
{
dm = [[DataManager alloc]init];
settings = [dm loadSettings];
if([dm hasConnectivity])
{
settings.lastUpdated = nil;
[dm storeSettings:settings];
}
if(settings.loadedCenter.centerCode != settings.chosenCenter.centerCode)
{
UIStoryboard *mystoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
SplashScreenController *controller = [mystoryboard instantiateViewControllerWithIdentifier:#"root"];
[self presentViewController:controller animated:YES completion:nil];
}
dm = nil;
settings = nil;
}
*/
}
-(void)gaVerder
{
_dm = [[DataManager alloc]init];
GSettings* settings = [_dm loadSettings];
if(settings == nil)
{
settings = [[GSettings alloc]init];
settings.notificationsEnabled = YES;
}
if(_center != nil)
{
settings.chosenCenter = _center;
}
[_dm storeSettings:settings];
[_mapView removeFromSuperview];
_mapView = nil;
_titleBackground = nil;
_lblTitle = nil;
_btnGaVerder = nil;
_myPickerView = nil;
_point = nil;
_indicator = nil;
_alert = nil;
_centers = nil;
_adresLine = nil;
_cityLine = nil;
_center = nil;
_dm = nil;
[self.presentingViewController dismissViewControllerAnimated:NO completion:^{}];
//DEZE BLIJFT HELAAS IN HET GEHEUGEN HANGEN... GEEN OPLOSSING GEVONDEN
//[self.navigationController popViewControllerAnimated:NO];
}
//PICKERVIEWDELEGATE EN DATASOURCE
// returns the number of 'columns' to display.
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
// returns the # of rows in each component..
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return [_centers count];
}
- (UILabel *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
GCenter* center = (GCenter*)[_centers objectAtIndex:row];
NSString* string = center.name;
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, pickerView.frame.size.width, 44)];
label.textColor = [GColor blueColor];
label.font = [label.font fontWithSize:18];
label.text = string;
label.textAlignment = NSTextAlignmentCenter;
return label;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
_center = (GCenter*)[_centers objectAtIndex:row];
[self changeAddressLines];
}
-(void)changeAddressLines
{
if (_mapView != nil)
{
[_mapView removeAnnotation:_point];
}
[_adresLine removeFromSuperview];
[_cityLine removeFromSuperview];
_adresLine = nil;
_cityLine = nil;
CGRect rctAdres = CGRectMake(0, _myPickerView.frame.origin.y + _myPickerView.frame.size.height -10, self.view.frame.size.width, 20);
_adresLine = [[UILabel alloc]initWithFrame:rctAdres];
_adresLine.textAlignment = NSTextAlignmentCenter;
_adresLine.textColor = [GColor greyColor];
_adresLine.text = _center.street;
CGRect rctCity = CGRectMake(0, rctAdres.origin.y + rctAdres.size.height, self.view.frame.size.width, 20);
_cityLine = [[UILabel alloc]initWithFrame:rctCity];
_cityLine.textAlignment = NSTextAlignmentCenter;
_cityLine.textColor = [GColor greyColor];
_cityLine.font = [_cityLine.font fontWithSize:14];
_cityLine.text = _center.city;
[self.view addSubview:_adresLine];
[self.view addSubview:_cityLine];
if(_mapView == nil)
{
double height;
height = _btnGaVerder.frame.origin.y - _cityLine.frame.origin.y - _cityLine.frame.size.height;
CGRect mapRect = CGRectMake(0, _cityLine.frame.origin.y+3 + _cityLine.frame.size.height, self.view.frame.size.width, height);
_mapView = [[MKMapView alloc]initWithFrame:mapRect];
[self.view addSubview:_mapView];
}
CLLocationCoordinate2D punt;
punt.latitude = _center.latitude;
punt.longitude = _center.longitude;
_point = [[MKPointAnnotation alloc] init];
[_point setCoordinate:punt];
_mapView.centerCoordinate = punt;
_point.title = _center.name;
[_mapView addAnnotation:_point];
[_mapView setCenterCoordinate:punt animated:YES];
MKCoordinateRegion theRegion = _mapView.region;
theRegion.span.longitudeDelta = 0.005;
theRegion.span.latitudeDelta = 0.005;
[_mapView setRegion:theRegion animated:YES];
}
#end
In my case it was a little more complicated. I don't have any variable that has strong reference to my view controller, and my view controller is not a strong delegate to any property/variable contained inside this class itself. After some hard thinking and trials, I found my issue was caused by a NSTimer object defined in the interface. The timer object itself is non-repeatable, but the method invoked by it will schedule the timer again at the end, which as you can imagine would reference this method defined in my view controller again, thus causing circular references. To break out of this loop, I had to invalidate the timer before I dismiss my view controller.
As a summary, these are cases when a view controller can be blocked from deallocating after it is dismissed:
The view controller is being strongly referenced by some outside object;
The view controller is a strong delegate referenced by some object defined within the view controller itself
The dismissViewControllerAnimated:completion: block may reference to self or it has some other code block that may cause a circular references
The view controller has NSTimer objects which can invoke some methods which re-schedules the timer
There could be more, but hopefully we can capture a lot of cases with the above cases.
If your view controller is not deallocated after it is dismissed, there's probably a strong reference to that view controller somewhere in your code. ARC will always deallocate objects that doesn't have strong reference anymore.
I would like to add the fade effect when user scroll my galleryViewController which fetch the data from the server. I could not able to implement the fade effect to my scrollViewController.
Code:
#import "GrillGalleryCollectionViewController.h"
#import "AFNetworking.h"
#interface GrillGalleryCollectionViewController ()
#end
#implementation GrillGalleryCollectionViewController
#synthesize scrollView,pageControl, colors;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// colors=[[NSArray alloc]init];
colors = [[NSArray alloc] init];;
[self getActiveOffers];
// NSArray *colors = [NSArray arrayWithObjects:[UIColor redColor], [UIColor greenColor], [UIColor blueColor], nil];
}
- (void)scrollViewDidScroll:(UIScrollView *)sender {
// Update the page when more than 50% of the previous/next page is visible
CGFloat pageWidth = self.scrollView.frame.size.width;
int page = floor((self.scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
self.pageControl.currentPage = page;
}
- (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.
}
*/
- (IBAction)changePage:(id)sender {
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * self.pageControl.currentPage;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
[self.scrollView scrollRectToVisible:frame animated:YES];
}
- (IBAction)backBtnPressed:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
pageControlBeingUsed = NO;
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
pageControlBeingUsed = NO;
}
- (void) getActiveOffers {
NSString *string = #"http://znadesign.com/appcenter/api.php?function=get_gallery&customer_id=1";
NSLog(#"%#", string);
NSURL *url = [NSURL URLWithString:string];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.responseSerializer = [AFJSONResponseSerializer serializer];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
int total_count = (int)[[responseObject valueForKey:#"total_count"] integerValue];
if (total_count > 0) {
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:total_count];
for (int i = 1; i <= total_count; i++) {
NSString *key = [NSString stringWithFormat:#"%i", i];
id object = [responseObject objectForKey:key];
[array addObject:object];
}
colors = [NSArray arrayWithArray:array];
[self setSizeSliding];
// [myTableView reloadData];
}
else
{
UIAlertView *alertView2 = [[UIAlertView alloc] initWithTitle:#"There is no internet connection."
message:nil
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView2 show];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// 4
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"There is no internet connection."
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alertView show];
}];
// 5
[operation start];
}
-(void) setSizeSliding
{
for (int i = 0; i < colors.count; i++) {
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * i;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
// UIView *subview = [[UIView alloc] initWithFrame:frame];
// subview.backgroundColor = [colors objectAtIndex:i];
// NSString *imageURLString=[[offersArray objectAtIndex:indexPath.row] valueForKey:#"picture"];
NSString*slidingImage = [[colors objectAtIndex:i] valueForKey:#"picture"];
NSURL *url = [NSURL URLWithString:slidingImage];
NSData *data = [[NSData alloc] initWithContentsOfURL:url];
UIImage *tmpImage = [[UIImage alloc] initWithData:data];
UIImageView *slidingImageView = [[UIImageView alloc]initWithFrame:frame];
slidingImageView.image = tmpImage;
[self.scrollView addSubview:slidingImageView];
}
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * colors.count, self.scrollView.frame.size.height);
}
#end
I want to implement the similar fade effect as it is listed below:
[UIView animateWithDuration:2
animations:^{imageView.alpha = 0.0;}
completion:^(BOOL finished){ [imageView removeFromSuperview];}];
You have the code Can you adding the below code and try whether the animation works..
-(void) animateSubViews
{
int buffer = 10;
CGRect frame = CGRectMake((self.pageControl.currentPage * self.scrollView.frame.size.width)-buffer, 0, self.scrollView.frame.size.width + buffer, self.scrollView.frame.size.height);
[UIView animateWithDuration:0.4
animations:^{
for (UIView *view in self.scrollView.subviews)
{
if (CGRectContainsRect(frame, view.frame))
{
[view setAlpha:1.0];
}
else
{
[view setAlpha:0.0];
}
}
}];
}
Try calling this method from ScrollView did scroll and change page.
- (IBAction)changePage:(id)sender {
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * self.pageControl.currentPage;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
[self.scrollView scrollRectToVisible:frame animated:YES];
//Call to animate
[self animateSubViews];
}
- (void)scrollViewDidScroll:(UIScrollView *)sender
{
// Update the page when more than 50% of the previous/next page is visible
CGFloat pageWidth = self.scrollView.frame.size.width;
int page = floor((self.scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
self.pageControl.currentPage = page;
//Call to animate
[self animateSubViews];
}
I am new to App Development, sorry if I am asking silly questions :(
I am developing a Quiz App. Whenever I give a right or wrong answer, an image appears with right or wrong answer result, however it stays for a few seconds, but after that - it does not continue with the next question. It just shows my background images with buttons. How can I set a code, that it goes straight to a new question, when the result image is gone.
I will be very thankful for your help.
I just want that after the Result-image closes, the quiz continues with the next question.
This is the code i have setup in Game.m file.
-(void)RightAnswer{
ScoreNumber = ScoreNumber + 1;
Score.text = [NSString stringWithFormat:#"%i", ScoreNumber];
Answer1.hidden = YES;
Answer2.hidden = YES;
Answer3.hidden = YES;
CategorySelected.hidden = NO;
Next.hidden = NO;
imageQuestion.hidden = YES;
Results.hidden = NO;
Results.image = [UIImage imageNamed:#"right.png"]; [self performSelector:#selector(Results) withObject:nil afterDelay:2.0];
GameInProgress = YES;
}
-(void)WrongAnswer{
LivesNumber = LivesNumber - 1;
Lives.text = [NSString stringWithFormat:#"%i", LivesNumber];
Answer1.hidden = YES;
Answer2.hidden = YES;
Answer3.hidden = YES;
imageQuestion.hidden = YES;
CategorySelected.hidden = NO;
Next.hidden = NO;
Results.hidden = NO;
Results.image = [UIImage imageNamed:#"wrong.png"];[self performSelector:#selector(Results) withObject:nil afterDelay:2.0];
GameInProgress = YES;
if(LivesNumber ==0) {
Results.image = [UIImage imageNamed:#"gameover.png"];
GameInProgress = NO;
Exit.hidden = NO;
}
-(void)RightAnswer{
ScoreNumber = ScoreNumber + 1;
Score.text = [NSString stringWithFormat:#"%i", ScoreNumber];
Answer1.hidden = YES;
Answer2.hidden = YES;
Answer3.hidden = YES;
Answer1Correct ==YES;
CategorySelected.hidden = NO;
Next.hidden = NO;
imageQuestion.hidden = YES;
Results.hidden = NO;
Results.image = [UIImage imageNamed:#"right.png"]; [self performSelector:#selector(Results) withObject:nil afterDelay:2.0];
GameInProgress = YES;
}
I think the issue is that you never set Answer1Correct to anything. so if you add Answer1Correct ==YES to the correct answer method and Answer1Correct ==NO to the wrong method then it should work
-(void)Results{ // just change formate of answer.
Results.hidden = YES;
}
-(IBAction)Answer1: (id) sender{
if (Answer1Correct ==YES) {
[self RightAnswer];
}else{
[self WrongAnswer];
}
}
-(IBAction)Answer2: (id) sender{
if (Answer2Correct ==YES) {
[self RightAnswer];
}
else{
[self WrongAnswer];
}
}
-(IBAction)Answer3: (id) sender{
if (Answer3Correct ==YES) {
[self RightAnswer];
}
else{
[self WrongAnswer];
}
}
i may be wrong here but I think you need an if to the else.
But I could be wrong.
if(LivesNumber ==0) {
Results.image = [UIImage imageNamed:#"gameover.png"];
GameInProgress = NO;
Exit.hidden = NO;
}else{
donextcard();
}
if you want to know how to make that function we would need to see more of the code.
Hey guys,
So.... lets say I have an NSArray of images
NSMutableArray *images = [NSMutableArray new];
[images addObject:[UIImage imageNamed:#"line1.png"]];
[images addObject:[UIImage imageNamed:#"line2.png"]];
[images addObject:[UIImage imageNamed:#"line3.png"]];
[images addObject:[UIImage imageNamed:#"line4.png"]];
Now I would like to load all these at once using a for loop but here is the catch.... I need to be able to set the images as hidden until the user unhides through interaction.
for (UIImage *image in images) {
UIImageView *line = [[UIImageView alloc] initWithImage:image];
line.hidden = YES;
[self.view addSubview:line];
}
But then how to I set the hidden BOOL to NO using another method?
As a secondary question, how would one release *line in the code above?
Thanks,
Darren
One option is to set up your images like:
int nextTag = 1;
for (UIImage *image in images) {
UIImageView *line = [[UIImageView alloc] initWithImage:image];
line.hidden = YES;
line.tag = nextTag;
[self.view addSubview:line];
[line release];
nextTag++;
}
...and then to unhide them you can do:
UIView* imageView = [self.view viewWithTag: lineNumber];
imageView.hidden = NO;
...assuming that your user-interaction handler is able to determine what line in the UI the user is interacting with.
As a secondary question, how would one release *line in the code above?
for (UIImage *image in images) {
UIImageView *line = [[UIImageView alloc] initWithImage:image];
line.hidden = YES;
[self.view addSubview:line]; // this retains the subview.
[line release]; // release line like this.
}
**
-(IBAction)btnReviewStar:(id)sender{
for (int i =([sender tag] ==30); i<36; i++) {
btnReviewStar.selected = NO;
btnReviewStar1.selected = NO;
btnReviewStar2.selected = NO;
btnReviewStar3.selected = NO;
btnReviewStar4.selected = NO;
if([sender tag] == 31) {
btnReviewStar.selected = YES;
break;
} else if([sender tag]==32) {
btnReviewStar.selected = YES;
btnReviewStar1.selected = YES;
break;
} else if([sender tag]==33) {
btnReviewStar.selected = YES;
btnReviewStar1.selected = YES;
btnReviewStar2.selected = YES;
break;
} else if([sender tag]==34) {
btnReviewStar.selected = YES;
btnReviewStar1.selected = YES;
btnReviewStar2.selected = YES;
btnReviewStar3.selected = YES;
break;
} else {
btnReviewStar.selected = YES;
btnReviewStar1.selected = YES;
btnReviewStar2.selected = YES;
btnReviewStar3.selected = YES;
btnReviewStar4.selected = YES;
break;
}
}
}
**