uitextfield and uilabel depends on checkmark - ios

In my tableview containing 8 row datas, I want to show the 8 label and 8 textfield in otherview, for ex: If the user selects(checkmarked) 4 rows in uitableview means I want to show 4 label and 4 texfield in other view. Can any one help me for this logic?
- (void)viewDidLoad
{
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"background.png"]];
[lb5 setHidden:YES];
[text5 setHidden:YES];
[lb6 setHidden:YES];
[text6 setHidden:YES];
//[lb7 setHidden:YES];
//[text7 setHidden:YES];
//[lb8 setHidden:YES];
//[text8 setHidden:YES];
scrollView.frame = CGRectMake(0, 0, 320, 460);
[scrollView setContentSize:CGSizeMake(320, 678)];
int s=[am.genar count];
am=(AppDelegate*)[[UIApplication sharedApplication] delegate];
NSLog(#"test %d",[am.genar count]);
NSLog(#"test %#",[am.genar objectAtIndex:0]);
lb1.text=[am.genar objectAtIndex:0];
NSLog(#"test %#",[am.genar objectAtIndex:1]);
lb2.text=[am.genar objectAtIndex:1];
NSLog(#"test %#",[am.genar objectAtIndex:2]);
lb3.text=[am.genar objectAtIndex:2];
NSLog(#"test %#",[am.genar objectAtIndex:3]);
lb4.text=[am.genar objectAtIndex:3];
if(s>3)
{
[lb5 setHidden:NO];
[text5 setHidden:NO];
[lb6 setHidden:NO];
[text6 setHidden:NO];
// [lb7 setHidden:NO];
// [text7 setHidden:NO];
// [lb8 setHidden:NO];
// [text8 setHidden:NO];;
NSLog(#"test %#",[am.genar objectAtIndex:4]);
lb5.text=[am.genar objectAtIndex:4];
NSLog(#"test %#",[am.genar objectAtIndex:5]);
lb6.text=[am.genar objectAtIndex:5];
// NSLog(#"test %#",[am.genar objectAtIndex:6]);
// lb7.text=[am.genar objectAtIndex:6];
// NSLog(#"test %#",[am.genar objectAtIndex:7]);
// lb8.text=[am.genar objectAtIndex:7];
}
[super viewDidLoad];
}
right now I'm using this logic for showing texfield and label, but it showing error if user selects 5 rows and it's working 6 rows. can any help me to clear?

Following your application design it might have sense to use the table view in the second view controller, it will be easy to create as many rows as needed and display the titles correctly.
If you need to use the outlet labels and textfields, i'd make it like
NSArray * arrayOfLabelsAndTextViews = [NSArray arrayWithObjects:lb1, text1, lb2, text2, lb3, text3, lb4, text4, lb5, text5, lx6, text6, lb7, text7, lb8, text8, nil];
With the help of this array you can quickly enumerate through all the label/text pairs accessing it as:
i - pair index
i*2 - label index
i*2 +1 - text index
Then you need to show exactly the number of pairs checked at the previos view:
am=(AppDelegate*)[[UIApplication sharedApplication] delegate];
const int totalPairsCount = 8;
for(int i = 0; i<totalPairsCount; i++) {
UILabel * pairLabel = [arrayOfLabelsAndTextViews objectAtIndex:i*2];
UITextView * pairText = [arrayOfLabelsAndTextViews objectAtIndex:i*2 +1];
BOOL isPairVisible = i < am.count;
if (isPairVisible) {
pairLabel.text = [am objectAtIndex:i];
pairText.text = #"";
}
pairLabel.hidden = !isPairVisible;
pairText.hidden = !isPairVisible;
}
I don't think that is production quality code but at list it must help you understand how do you operate the data and use the UI elements.

dont code like this..,
int s=[am.genar count];
am=(AppDelegate*)[[UIApplication sharedApplication] delegate];
add S values after declaration of AppDelegate Variable.,
am=(AppDelegate*)[[UIApplication sharedApplication] delegate];
int s=[am.genar count];
and try to print the values.,.

On Click of Check Mark add that particular string to an Global Array. From that you can get an Global array count
In Second View
View Did Load Method
create a for loop
(int i =0 ; i < appDelegate.globalArray; i++)
{
Here you can create a label Dynamically whatever number will be. your labels will create according to that
}
if you have any questions feel free to ask

Related

Keep Button State Selected in UICollection view with horizontal scroll

I am following this example
I have added a button in the view
On selection the button image change to Green icon image.
How could I retain it using this example?
I had updated the existing code of your example to your requirement please find the below url for download the code and review it.
Link : https://www.dropbox.com/s/6xsr4o88khyijun/HorizontalTables.zip?dl=0
Highlight of the code which I had done it.
1) Take the NSMutableArray *arrSelection property in HorizontalTablesAppDelegate class.
2) Fill the data of arrSelection in ArticleListViewController_iPhone class of viewDidLoad method.
for (NSInteger i = 0; i < [self.articleDictionary.allKeys count]; i++)
{
HorizontalTableCell_iPhone *cell = [[HorizontalTableCell_iPhone alloc] initWithFrame:CGRectMake(0, 0, 320, 416) tag:i];
categoryName = [sortedCategories objectAtIndex:i];
currentCategory = [self.articleDictionary objectForKey:categoryName];
cell.articles = [NSArray arrayWithArray:currentCategory];
if(i == 0)
appDelegate.arrSelection = [[NSMutableArray alloc] init];
NSMutableArray *arrSubData = [[NSMutableArray alloc] init];
for(NSInteger j=0; j<currentCategory.count; j++)
[arrSubData addObject:[NSNumber numberWithBool:NO]];
[appDelegate.arrSelection addObject:arrSubData];
[arrSubData release];
[self.reusableCells addObject:cell];
[cell release];
}
3) On HorizontalTableCell_iPhone class of cellForRowAtIndexPath method
NSMutableArray *arrSelectionInfo = appDelegate.arrSelection[tableView.tag];
BOOL isSelect = [arrSelectionInfo[indexPath.row] boolValue];
if(isSelect)
[cell.btnSelection setBackgroundColor:[UIColor greenColor]];
else
[cell.btnSelection setBackgroundColor:[UIColor whiteColor]];
And didSelectRowAtIndexPath method
NSMutableArray *arrUpdate = appDelegate.arrSelection[tableView.tag];
[arrUpdate replaceObjectAtIndex:indexPath.row withObject:[NSNumber numberWithBool:YES]];
[tableView reloadData];
Hope this will work for you.
To keep button state selected you need to store information of selection on a dictionary for the cell. So once cell is reloaded, you can apply selection setting based on information you have.
There is no direct way (even if there was you should now use that, as it will lead to memory abuse) to keep it selected all the time.

VFL with Xcode for Auto Layout

I have an existing application that has the positioning of all the elements written in code rather then in auto-layout. I am trying to use that existing code to add Auto-Layout for those elements.
I am trying to have the two buttons xButton and checkButton to show up at the bottom of the screen next to each other, which will work for all iPhone screens. The current behavior is that the buttons are offset towards the bottom of the screen.
Below is my code where my VFL is located - however this is placed in a UIView instead of a ViewController.
I have tried to figure this out on my own but no luck, I would love it if someone could give me a hand with this topic as well as this certain issue.
Thank you
#implementation DraggableViewBackground{
NSInteger cardsLoadedIndex; //%%% the index of the card you have loaded into the loadedCards array last
NSMutableArray *loadedCards; //%%% the array of card loaded (change max_buffer_size to increase or decrease the number of cards this holds)
UIButton* checkButton;
UIButton* xButton;
}
//this makes it so only two cards are loaded at a time to
//avoid performance and memory costs
static const int MAX_BUFFER_SIZE = 2; //%%% max number of cards loaded at any given time, must be greater than 1
static const float CARD_HEIGHT = 386; //%%% height of the draggable card
static const float CARD_WIDTH = 290; //%%% width of the draggable card
#synthesize exampleCardLabels; //%%% all the labels I'm using as example data at the moment
#synthesize allCards;//%%% all the cards
- (void)loadView {
[self setupView];
exampleCardLabels = [[NSArray alloc]initWithObjects:#"Are you in the Technology Industry?",#"Do you have more then 3 years of work experiance?",#"Do you have more then 3 years of work experiance?",#"Are you willing to relocate?",#"Did you enjoy this app?", nil]; //%%% placeholder for card-specific information
loadedCards = [[NSMutableArray alloc] init];
allCards = [[NSMutableArray alloc] init];
cardsLoadedIndex = 0;
[self loadCards];
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[super layoutSubviews];
[self setupView];
exampleCardLabels = [[NSArray alloc]initWithObjects:#"Are you in the Technology Industry?",#"Do you have more then 3 years of work experiance?",#"Do you have more then 3 years of work experiance?",#"Are you willing to relocate?",#"Did you enjoy this app?", nil]; //%%% placeholder for card-specific information
loadedCards = [[NSMutableArray alloc] init];
allCards = [[NSMutableArray alloc] init];
cardsLoadedIndex = 0;
[self loadCards];
}
return self;
}
//%%% sets up the extra buttons on the screen
// VFL Visual Formal Language -
- (void)setupView {
#warning customize all of this. These are just place holders to make it look pretty
self.backgroundColor = [UIColor colorWithRed:.92 green:.93 blue:.95 alpha:1]; //the gray background colors
xButton = [[UIButton alloc]initWithFrame:CGRectMake(60, CGRectGetHeight(self.frame)- 100, 59, 59)];
[xButton setImage:[UIImage imageNamed:#"xButton"] forState:UIControlStateNormal];
[xButton addTarget:self action:#selector(swipeLeft) forControlEvents:UIControlEventTouchUpInside];
[xButton setTranslatesAutoresizingMaskIntoConstraints:NO];
[xButton setBackgroundColor:[UIColor redColor]];
checkButton = [[UIButton alloc]initWithFrame:CGRectMake(200, CGRectGetHeight(self.frame)- 100, 59, 59)];
[checkButton setImage:[UIImage imageNamed:#"checkButton"] forState:UIControlStateNormal];
[checkButton addTarget:self action:#selector(swipeRight) forControlEvents:UIControlEventTouchUpInside];
[checkButton setTranslatesAutoresizingMaskIntoConstraints:NO];
[checkButton setBackgroundColor:[UIColor blueColor]];
[self addSubview:xButton];
[self addSubview:checkButton];
}
#warning include own card customization here!
//%%% creates a card and returns it. This should be customized to fit your needs.
// use "index" to indicate where the information should be pulled. If this doesn't apply to you, feel free
// to get rid of it (eg: if you are building cards from data from the internet)
-(DraggableView *)createDraggableViewWithDataAtIndex:(NSInteger)index
{
DraggableView *draggableView = [[DraggableView alloc]initWithFrame:CGRectMake((self.frame.size.width - CARD_WIDTH)/2,(self.frame.size.height - CARD_HEIGHT)/2, CARD_WIDTH, CARD_HEIGHT)];
draggableView.information.text = [exampleCardLabels objectAtIndex:index];//%%% placeholder for card-specific information
draggableView.delegate = self;
return draggableView;
}
//%%% loads all the cards and puts the first x in the "loaded cards" array
-(void)loadCards
{
if([exampleCardLabels count] > 0) {
NSInteger numLoadedCardsCap =(([exampleCardLabels count] > MAX_BUFFER_SIZE)?MAX_BUFFER_SIZE:[exampleCardLabels count]);
//%%% if the buffer size is greater than the data size, there will be an array error, so this makes sure that doesn't happen
//%%% loops through the exampleCardsLabels array to create a card for each label. This should be customized by removing "exampleCardLabels" with your own array of data
for (int i = 0; i<[exampleCardLabels count]; i++) {
DraggableView* newCard = [self createDraggableViewWithDataAtIndex:i];
[allCards addObject:newCard];
if (i<numLoadedCardsCap) {
//%%% adds a small number of cards to be loaded
[loadedCards addObject:newCard];
}
}
//%%% displays the small number of loaded cards dictated by MAX_BUFFER_SIZE so that not all the cards
// are showing at once and clogging a ton of data
for (int i = 0; i<[loadedCards count]; i++) {
if (i>0) {
[self insertSubview:[loadedCards objectAtIndex:i] belowSubview:[loadedCards objectAtIndex:i-1]];
} else {
[self addSubview:[loadedCards objectAtIndex:i]];
}
cardsLoadedIndex++; //%%% we loaded a card into loaded cards, so we have to increment
}
}
}
#warning include own action here!
//%%% action called when the card goes to the left.
// This should be customized with your own action
-(void)cardSwipedLeft:(UIView *)card;
{
//do whatever you want with the card that was swiped
// DraggableView *c = (DraggableView *)card;
[loadedCards removeObjectAtIndex:0]; //%%% card was swiped, so it's no longer a "loaded card"
if (cardsLoadedIndex < [allCards count]) { //%%% if we haven't reached the end of all cards, put another into the loaded cards
[loadedCards addObject:[allCards objectAtIndex:cardsLoadedIndex]];
cardsLoadedIndex++;//%%% loaded a card, so have to increment count
[self insertSubview:[loadedCards objectAtIndex:(MAX_BUFFER_SIZE-1)] belowSubview:[loadedCards objectAtIndex:(MAX_BUFFER_SIZE-2)]];
}
}
#warning include own action here!
//%%% action called when the card goes to the right.
// This should be customized with your own action
-(void)cardSwipedRight:(UIView *)card
{
//do whatever you want with the card that was swiped
// DraggableView *c = (DraggableView *)card;
[loadedCards removeObjectAtIndex:0]; //%%% card was swiped, so it's no longer a "loaded card"
if (cardsLoadedIndex < [allCards count]) { //%%% if we haven't reached the end of all cards, put another into the loaded cards
[loadedCards addObject:[allCards objectAtIndex:cardsLoadedIndex]];
cardsLoadedIndex++;//%%% loaded a card, so have to increment count
[self insertSubview:[loadedCards objectAtIndex:(MAX_BUFFER_SIZE-1)] belowSubview:[loadedCards objectAtIndex:(MAX_BUFFER_SIZE-2)]];
}
}
//%%% when you hit the right button, this is called and substitutes the swipe
-(void)swipeRight
{
DraggableView *dragView = [loadedCards firstObject];
dragView.overlayView.mode = GGOverlayViewModeRight;
[UIView animateWithDuration:0.2 animations:^{
dragView.overlayView.alpha = 1;
}];
[dragView rightClickAction];
}
//%%% when you hit the left button, this is called and substitutes the swipe
-(void)swipeLeft
{
DraggableView *dragView = [loadedCards firstObject];
dragView.overlayView.mode = GGOverlayViewModeLeft;
[UIView animateWithDuration:0.2 animations:^{
dragView.overlayView.alpha = 1;
}];
[dragView leftClickAction];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
#end
To achieve what you want to do with the buttons you can use VFL like this:
self.view.translatesAutoresizingMaskIntoConstraints = NO;
button1.translatesAutoresizingMaskIntoConstraints = NO;
button2.translatesAutoresizingMaskIntoConstraints = NO;
NSDictionary *viewsDict = #{#"button1": button1, #"button2": button2};
NSArray *horizontalContraints = [NSLayoutConstraint constraintsWithVisualFormat:#"H:|-[button1(150)][button2(150)]-|"
options:NSLayoutFormatAlignAllBottom
metrics:nil
views:viewsDict];
NSArray *verticalConstraintsButton1 = [NSLayoutConstraint constraintsWithVisualFormat:#"V:[button1]-20-|"
options:NSLayoutFormatAlignAllCenterX
metrics:nil
views:viewsDict];
NSArray *verticalConstraintsButton2 = [NSLayoutConstraint constraintsWithVisualFormat:#"V:[button2]-20-|"
options:NSLayoutFormatAlignAllCenterX
metrics:nil
views:viewsDict];
[self.view addConstraints:horizontalContraints];
[self.view addConstraints:verticalConstraintsButton1];
[self.view addConstraints:verticalConstraintsButton2];
This give the buttons each a width of 150 pt and places them 20 pt from the left, right and bottom of your view.

Xcode: Remove an array of textiews from screen

I'm currently adding 5 textviews onto the viewcontroller programatically inside the viewDidLoad method.
for (int i = 0; i < 5; i++) {
//Add 5 textviews
UITextView *reqTV = [[UITextView alloc] initWithFrame:CGRectMake(30,30,250,50)];
reqTV.text = #"This is a textview";
[self.view addSubview:reqTV];
}
If later, I want to delete (not hide) these 5 textviews with a button click, how would I do that?
I have thought of using this, but am not sure how to call all 5 textviews to delete them.
- (void)removeTextViewButton:(id)sender {
[reqTV removeFromSuperview]; //remove textview
}
Thank you.
I see two easy ways:
You can save your textViews inside array as ivar of your controller.
And later remove each textView in array.
for (int i = 0; i < 5; i++) {
...
[textViews addObject: reqTV];
...
}
- (void)removeTextViewButton:(UIButton *)sender {
[textViews makeObjectsPerformSelector:#selector(removeFromSuperview)];
}
2. Assign static tag for each textView:
for (int i = 0; i < 5; i++) {
...
reqTV.tag = 1001; // for example
}
- (void)removeTextViewButton:(UIButton *)sender {
NSArray *subs = [NSArray arrayWithArray: self.view.subviews];
for (UIView *sub in subs) {
if (sub.tag == 1001) {
[sub removeFromSuperview];
}
}
}
Used code below to remove UITextViews:
- (void)removeTextViewButton:(id)sender {
NSArray *reqTVViews = [NSArray arrayWithArray: self.view.subviews];
for (UIView *tvView in reqTVViews) {
if ([tvView isKindOfClass:[UITextView class]]) {
[tvView removeFromSuperview];
}
}
}
When you are adding UITextFields on viewController use tag value to uniquely identify each textField.
You can store each tag value in an array for further use, eg.
#property (nonatomic, strong) NSMutableArray *tagArray;
NSMutableArray *tagArray = [NSMutableArray array];
for (int i = 101; i <= 105; i++ ) {
UITextField *txt = [UITextField alloc] init]; //for eg.
...
...
txt.tag = i;
[arr addObject:[NSNumber numberWithInt:i]];
[self.view addSubView:txt];
}
When you want to delete any of the textField or all then...
UIView *view = [self.view viewWithTag:<tag value>];
[view removeFromSuperview];
eg.
for (int i = 0; i < tagArray.count; i++) {
NSInteger tag = [[arr objectAtIndex:i] intValue];
UITextField *txt = (UITextField *)[self.view viewWithTag:tag];
[txt removeFromSuperview];
}
You can remove all subview in one go
- (void)removeTextViewButton:(id)sender
{
for (UIView *subview in views.subviews)
{
[subview removeFromSuperview];
}
}
Happy Coding.. :)

How to Pass Multiple images to other View at a time?

In my app I'm picking five images at a time and displaying in a small view and I have button if I click that button the 5 images in that view should go to next View Controller .but when I'm clicking that button only the image in 0th index is passing and remaining images are not passing.Hope someone helps me
And here is my code.This code is for passing from first view to second view and chosenImages is an array where all the picked images are saving
SecondViewController *secview=[[SecondViewController alloc]initWithNibName:#"SecondViewController" bundle:nil];
if (secview.imgView.tag==0) {
secview.img=[self.chosenImages objectAtIndex:0];
}
else if (secview.imgView1.tag==1)
{
secview.img=[self.chosenImages objectAtIndex:1];
}
else if (secview.imgView1.tag==2)
{
secview.img=[self.chosenImages objectAtIndex:2];
}
else if (secview.imgView1.tag==3)
{
secview.img=[self.chosenImages objectAtIndex:3];
}
else if (secview.imgView1.tag==4)
{
secview.img=[self.chosenImages objectAtIndex:4];
}
NSLog(#"%#",secview.img);
[self presentViewController:secview animated:YES completion:nil];
and in second view my code is:
if (imgView.tag==0)
{
imgView.image=img;
}
else if (imgView1.tag==1)
{
imgView1.image=img;
}
else if (imgView2.tag==2)
{
imgView2.image=img;
}
else if (imgView3.tag==3)
{
imgView3.image=img;
}
else if (imgView4.tag==4)
{
imgView4.image=img;
}
Update:In didFinishPickingMedia I wrote this code
images = [NSMutableArray arrayWithCapacity:[info count]];
for (NSDictionary *dict in info) {
if ([dict objectForKey:UIImagePickerControllerMediaType] == ALAssetTypePhoto){
if ([dict objectForKey:UIImagePickerControllerOriginalImage]){
image=[dict objectForKey:UIImagePickerControllerOriginalImage];
[images addObject:image];
UIImageView *imageview = [[UIImageView alloc] initWithImage:image];
[imageview setContentMode:UIViewContentModeScaleAspectFit];
}
}
else {
NSLog(#"UIImagePickerControllerReferenceURL = %#", dict);
}
}
self.chosenImages = images;
[AllImages setHidden:NO];
previousButtonTag=1000;
scrollView=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 4, self.AllImages.frame.size.width, 104)];
int x =0.5;
for (int i=0; i<5; i++) {
button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame=CGRectMake(x, 0, 100, 123);
button.layer.borderWidth=0.5;
button.titleLabel.font=[UIFont boldSystemFontOfSize:12];
button.titleLabel.textAlignment = NSTextAlignmentCenter;
button.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
// button.layer.borderColor=[[UIColor lightGrayColor]CGColor];
button.tag = i;
[button setBackgroundImage:[self.chosenImages objectAtIndex:i] forState:UIControlStateNormal];
[button addTarget:self action:#selector(OverLayMethod:) forControlEvents:UIControlEventTouchUpInside];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[scrollView addSubview:button];
x += button.frame.size.width;
x=x+6.0;
}
scrollView.contentSize = CGSizeMake(x, scrollView.frame.size.height);
scrollView.backgroundColor = [UIColor clearColor];
[self.AllImages addSubview:scrollView];
}
I solved my issue by declaring another array in second view.In first view we are saving picked images in one array .so that first view array objects = second view array and I passed that array in second view
my code in second view :
for (int i=0; i<[arr count]; i++) {
self.img=[arr objectAtIndex:i];
if (i==0)
{
imgView.image=img;
}
else if (i==1)
{
imgView1.image=img;
}
else if (i==2)
{
imgView2.image=img;
}
else if (i==3)
{
imgView3.image=img;
}
else if (i==4)
{
imgView4.image=img;
}
}
}
by this i'm getting correct output
I dunno that I got your question but my understanding is that you wanna send 5 images to another view. If so, define a new NSArray property such as 'images' in your SecondViewController and add it to where you go from first view to second
SecondViewController *secondVC = [SecondViewController new];
[secondVC setImages: self.chosenImages];
The problem with your code is that you're using if/else if block statement and if one of the conditions in that if/else if evaluate to true only you get into one of the block. Also, -objectAtIndex: only returns one item.
[self.chosenImages objectAtIndex:0];
Also, I'm sure that secview.img means that you have a UIImage property inside your SecondViewController.

Reload UIScrollView by tapping a UIButton

Let me explain my project first. I have some data in my SQLIte DB table called "note".
In "note" table I have these fields: id, noteToken, note.
What I am doing here is load all the note in an NSMUtableArray from that table. And create UIButton according to that array content number and add those buttons in a UIScrollView as subView. The number of buttons and width of scrollview generate auto according to the number of content of that array. Now, when some one tap one of those Buttons, it will bring him to a next viewController and show him the corresponding note details in that viewController.
I do the same thing with another NSMUtableArray, but these time it read all the id from the "note" table. It equally generate new delete button in the same UIScrollView. But if some one tap on these delete button it will delete that particular note from the table "note" of SQLIte DB. AND RELOAD THE UIScrollView. All are done except the RELOAD THE UIScrollView part. This is what I want. I tried with all exist solution but don't know why it's not working.
Here is my code:
- (void)viewDidLoad
{
[super viewDidLoad];
self.noteToken = [NSString stringWithFormat:#"%#%#", fairId, exibitorId];
scrollViewNoteWidth = 100;
[scrollViewNote setScrollEnabled:YES];
[scrollViewNote setContentSize:CGSizeMake((noteButtonWidth * countNoteButtonArray) + scrollViewNoteWidth, 100)];
sqLite = [[SQLite alloc] init];
[self.sqLite callDataBaseAndNoteTableMethods];
self.noteButtonArrayy = [[NSMutableArray alloc] init];
noteButtonArrayy = [self.sqLite returnDataFromNoteTable:noteToken];
[self LoadNoteButtonAndDeleteButton:noteButtonArrayy];
}
//////////////*----------------------- Note Section (Down) -----------------------*//////////////
-(void) LoadNoteButtonAndDeleteButton:(NSMutableArray *) noteButtonArray
{
sQLiteClass = [[SQLiteClass alloc] init];
noteButtonArrayToShowNoteButton = [[NSMutableArray alloc] init];
/*--------------- Load the noteButton & pass note (Down)---------------*/
for (int i = 0; i < [noteButtonArray count]; i++)
{
sQLiteClass = [noteButtonArray objectAtIndex:i];
// NSString *ids = [NSString stringWithFormat:#"%d", sQLiteClass.idNum];
NSString *nt = sQLiteClass.note;
[noteButtonArrayToShowNoteButton addObject:nt];
}
[self ShowNoteButtonMethod:noteButtonArrayToShowNoteButton];
/*--------------- Load the noteButton & pass note (Up)---------------*/
/*--------------- Load the deleteButton & pass id (Down)---------------*/
noteButtonArrayToDeleteNoteButton = [[NSMutableArray alloc] init];
for (int i = 0; i < [noteButtonArray count]; i++)
{
sQLiteClass = [noteButtonArray objectAtIndex:i];
// Convert int into NSString
NSString *ids = [NSString stringWithFormat:#"%d", sQLiteClass.idNum];
[noteButtonArrayToDeleteNoteButton addObject:ids];
}
[self ShowNoteDeleteButtonMethod:noteButtonArrayToDeleteNoteButton];
/*--------------- Load the deleteButton & pass id (Down)---------------*/
}
-(void) ShowNoteButtonMethod:(NSMutableArray *) btnarray
{
countNoteButtonArray = [btnarray count];
// For note button
noteButtonWidth = 60;
noteButtonXposition = 8;
for (NSString *urls in btnarray)
{
noteButtonXposition = [self addNoteButton:noteButtonXposition AndURL:urls];
}
}
-(int) addNoteButton:(int) xposition AndURL:(NSString *) urls
{
noteButton =[ButtonClass buttonWithType:UIButtonTypeCustom];
noteButton.frame = CGRectMake(noteButtonXposition, 8.0, noteButtonWidth, 60.0);
[noteButton setImage:[UIImage imageNamed:#"note.png"] forState:UIControlStateNormal];
[noteButton addTarget:self action:#selector(tapOnNoteButton:) forControlEvents:UIControlEventTouchUpInside];
[noteButton setUrl:urls];
noteButton.backgroundColor = [UIColor clearColor];
[self.scrollViewNote addSubview:noteButton];
noteButtonXposition = noteButtonXposition + noteButtonWidth + 18;
return noteButtonXposition;
}
-(void)tapOnNoteButton:(ButtonClass*)sender
{
urlNote = sender.url;
[self performSegueWithIdentifier:#"goToNoteDetailsViewController" sender:urlNote];
}
-(void) ShowNoteDeleteButtonMethod:(NSMutableArray *) btnarray
{
countNoteButtonArray = [btnarray count];
// For delete button
deleteNoteButtonWidth = 14;
deleteNoteButtonXposition = 31;
for (NSString *idNumber in btnarray)
{
deleteNoteButtonXposition = [self addDeleteButton:deleteNoteButtonXposition AndURL:idNumber];
}
}
-(int) addDeleteButton:(int) xposition AndURL:(NSString *) idNumber
{
deleteNoteButton =[ButtonClass buttonWithType:UIButtonTypeCustom];
deleteNoteButton.frame = CGRectMake(deleteNoteButtonXposition, 74.0, deleteNoteButtonWidth, 20.0);
[deleteNoteButton setImage:[UIImage imageNamed:#"delete.png"] forState:UIControlStateNormal];
[deleteNoteButton addTarget:self action:#selector(tapOnDeleteButton:) forControlEvents:UIControlEventTouchUpInside];
[deleteNoteButton setIdNum:idNumber];
deleteNoteButton.backgroundColor = [UIColor clearColor];
[self.scrollViewNote addSubview:deleteNoteButton];
deleteNoteButtonXposition = deleteNoteButtonXposition + deleteNoteButtonWidth + 65;
return deleteNoteButtonXposition;
}
-(void)tapOnDeleteButton:(ButtonClass*)sender
{
idNumb = sender.idNum;
[self.sqLite deleteData:[NSString stringWithFormat:#"DELETE FROM note WHERE id IS '%#'", idNumb]];
// NSLog(#"idNumb %#", idNumb);
//[self.view setNeedsDisplay];
//[self.view setNeedsLayout];
//[self LoadNoteButtonAndDeleteButton];
//[self viewDidLoad];
// if ([self isViewLoaded])
// {
// //self.view = Nil;
// //[self viewDidLoad];
// [self LoadNoteButtonAndDeleteButton];
// }
}
//////////////*----------------------- Note Section (Up) -----------------------*//////////////
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"goToNoteDetailsViewController"])
{
NoteDetailsViewController *noteDetailsViewController = [segue destinationViewController];
[noteDetailsViewController setUrl:sender];
}
}
Here's the screen shot:
Here we can feel the difference between UIScrollView and UICollectionView, however UICollectionView is made up of UIScrollView, UICollectionView can be reload and adjust its content accordingly, where UIScrollView can't.
Ok, now in your case, you've to reload (refresh) your scroll view, which is not possible as we can with UICollectionView or UITableView.
You've two options,
Best option (little tough) : replace UIScrollView with UICollectionView - will take some of your time, but better for reducing code complexity and good performance of your app.
Poor option (easy) : Stay as it with UIScrollView - when you want to reload, delete each subview from it, and then again show and load everything. Highly not recommended.
IMHO, you should go with best option.

Resources