ICoder
ICoder

Reputation: 1347

How to set a image enabled when a action is already done?

I am working on a bible reader application for iphone. When we click on any verse of the bible it pops up a menu which contains some controllers like bookmark, notes view etc. The note view has a hidden tick mark. My requirement is as follows :

  1. User should be able to select a verse, add a note to it and save it
  2. When the same verse is selected again, the tick mark should appear indicating that a note has already been added.

My code is

-(IBAction)_clickbtnNotesMain:(id)sender
{

    [self.view addSubview:NoteView];
    _lblnotegns.text = localStringValueverseno;//localStringValueverseno which holds the verse no: from the tableview,the verse and verse no: shown in tableview
//NoteView is the notepopup ie,write note in Noteview
}
-(IBAction)_clickbtnsaveNote:(id)sender
{
[delegate.indexArray addObject:[NSString stringWithFormat:@"%@ %@:%@",delegate.selectedBook,delegate.selectedChapter,delegate.selectedIndex]];
    [delegate.notesArray addObject:textView.text];
    NSString *DataPath = [Malayalam_BibleAppDelegate getPath];
    [delegate.data writeToFile:DataPath atomically:YES];
    proAlertView *alert = [[proAlertView alloc]initWithTitle:@"NOTES" message:@"Notes Saved" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
    [alert setBackgroundColor:[UIColor colorWithRed:0.255 green:0.218 blue:0.185 alpha:1.0] withStrokeColor:[UIColor colorWithHue:0.625 saturation:0.0 brightness:0.8 alpha:0.8]];
    [alert show];
    [alert release];
    }

With the above code I save the note. It is displayed in a tableviewcontroller which the user can see if he wants.

UPDATE:

-(IBAction)_clickbtnsaveNote:(id)sender
{
[delegate.indexArray addObject:[NSString stringWithFormat:@"%@ %@:%@",delegate.selectedBook,delegate.selectedChapter,delegate.selectedIndex]];
[delegate.notesArray addObject:textView.text];
    [notes setValue:textView.text forKey:[NSString stringWithFormat:@"%@ %@:%@",delegate.selectedBook,delegate.selectedChapter,delegate.selectedIndex]];
NSString *DataPath = [Malayalam_BibleAppDelegate getPath];
[delegate.data writeToFile:DataPath atomically:YES];
proAlertView *alert = [[proAlertView alloc]initWithTitle:@"NOTES" message:@"Notes Saved" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
    [alert setBackgroundColor:[UIColor colorWithRed:0.255 green:0.218 blue:0.185 alpha:1.0] withStrokeColor:[UIColor colorWithHue:0.625 saturation:0.0 brightness:0.8 alpha:0.8]];
    [alert show];
    [alert release];
}

then in my popup comes view that is mainpopup,it comes when i tap the cell codeis

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {


    if ([notes objectForKey:[NSString stringWithFormat:@"%@ %@:%@",delegate.selectedBook,delegate.selectedChapter,delegate.selectedIndex]] == nil) {
        [notetickimage setHidden:YES];
        [self.view addSubview:MainPopupView];
    }


}

Upvotes: 1

Views: 101

Answers (2)

anasaitali
anasaitali

Reputation: 1514

Have you tried this :

[yourBtnOrImage setHidden:YES];

or

[yourBtnOrImage setEnabled:YES];

You just have to check if there is already a note on a verse if yes use the code above, otherwise use the code below :

[yourBtnOrImage setHidden:NO];

or

[yourBtnOrImage setEnabled:NO];

I hope its what you are looking for.

UPDATE :

NSMutableDictionary *notes = [[NSMutableDictionary alloc] init]; //Initialize like that for you
//Add a note :
[notes setValue:textView.text forKey:[NSString stringWithFormat:@"%@ %@:%@",delegate.selectedBook,delegate.selectedChapter,delegate.selectedIndex]];

Code to check if a note exist :

if ([notes objectForKey:[NSString stringWithFormat:@"%@ %@:%@",delegate.selectedBook,delegate.selectedChapter,delegate.selectedIndex]] == nil) {
        [yourBtnOrImage setHidden:YES];
    }

Upvotes: 1

Manali
Manali

Reputation: 573

There could be several ways to do this, one that I could think of is : In your delegate.notesArray add a field for verse number. While displaying the verse run through the array and check if the particular verse has a note attached to it. EDIT: Oh Yes, like A10 says NSMutableDictionnary might prove easier

Upvotes: 0

Related Questions