Share code between two files/classes

Hey,
in my AppDelegate.m I have a UITextField, in another ViewController.m I want to display an alert if the UITextField has a special text.
How can I share this code, or how can I reach the TextField.text in my other ViewController?
Thanks for help!

I think the easiest way to do it might be to use NSNotificationCenter. I'm not sure if I understand your problem right, but if it's what I think it is, in your AppController, add the following code whenever the text field is updated:
/*You must have the string for your text field in a variable named textString.
If you are calling it something different, you can change what the variable name
is in the second line of the code with the NSDictionary.*/
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
NSDictionary *info = [NSDictionary dictionaryWithObject:textString forKey:@"text"];
[notificationCenter postNotificationName:@"TextFieldChanged" object:self userInfo:info];
Then, in your view, add this to your init method:
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter addObserver:self
selector:@selector(textFieldChanged:)
name:@"TextFieldChanged"
object:nil];
Now, you have to implement the textFieldChanged: method in your view controller like this:
-(void)textFieldChanged:(NSNotification *)notification {
NSLog(@"Received notification.");
NSString *string = [[notification userInfo] objectForKey:@"text"];
//Your code to display an alert.
I hope that helps.

Similar Messages

  • Share info between two files ?

    hello, is it possible to collect automatically information of 1 cell of 1 file into a cell of another file ?
    tx for your help
    s

    Hello
    I enhanced the script.
    (1) corrected some errors
    (2) add the ability to use a special kind of references into the source document.
    Footer colNum may be used to grab the bottom cell in the column colNum.
    The beast is available on my iDisk with sample files.
    <http://idisk.me.com/koenigyvan-Public?view=web>
    Download:
    For_iWork:iWork '09:for_Numbers09:fromDoc#1toDoc#2.dmg.zip
    --[SCRIPT fromDoc#1toDoc#2]
    Enregistrer le script en tant que Script, Application ou Progiciel : fromDoc#1toDoc#2.xxx
    déplacer l’application créée dans le dossier
    <VolumeDeDémarrage>:Users:<votreCompte>:Library:Scripts:Applications:Numbers:
    Il vous faudra peut-être créer le dossier Numbers et peut-être même le dossier Applications.
    menu Scripts > Numbers > fromDoc#1toDoc#2
    Naviguer pour choisir un document texte contenant les paramètres décrivant le traitement à effectuer.
    En fonction de ces paramètres, le script ouvrira deux documents Numbers et copieradans le second des valeurs prélevées dans le premier.
    Voici un exemple de fichier texte des paramètres:
    Macintosh HD:Users:yvan_koenig:Desktop:
    Source.numbers
    Feuille 1
    Tableau 1
    Macintosh HD:Users:yvan_koenig:Desktop:
    Destination.numbers
    Feuille 18
    Tableau 12
    4
    D4
    E4
    D8
    E8
    D4
    E4
    D8
    E8
    ligne1 contient le chemin d'accès au dossier contenant le document source
    ligne2 contient le nom du document source
    ligne3 contient le nom de la feuille source
    ligne4 contient le nom de la table source
    ligne5 contient le chemin d'accès au dossier contenant le document destination
    ligne6 contient le nom du document destination
    ligne7 contient le nom de la feuille destination
    ligne8 contient le nom de la table destination
    ligne9 contient le nombre de valeurs à extraire/insérer
    viennent ensuite les références des cellules sources
    suivies des références des cellules destination
    Pied de page numéroDeColonne peut être utilisé pour référencer la cellule la plus basse de la colonne numéroDeColonne.
    --=====
    L'aide du Finder explique:
    L'Utilitaire AppleScript permet d'activer le Menu des scripts :
    Ouvrez l'Utilitaire AppleScript situé dans le dossier Applications/AppleScript.
    Cochez la case "Afficher le menu des scripts dans la barre de menus".
    =+=+=+=+=+=+=+=
    Save the script as a Script, an Application or an Application Bundle: fromDoc#1toDoc#2.xxx
    Move the newly created application into the folder:
    <startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Numbers:
    Maybe you would have to create the folder Numbers and even the folder Applications by yourself.
    menu Scripts > Numbers > fromDoc#1toDoc#2
    Navigate to choose a text document containing the parameters describing the operations to execute.
    Give these parameters, the script will open two Numbers documents and copy in the second one a set of values grabbed from the first one.
    Here is a sample of the parameters text file:
    Macintosh HD:Users:yvan_koenig:Desktop:
    Source.numbers
    Feuille 1
    Tableau 1
    Macintosh HD:Users:yvan_koenig:Desktop:
    Destination.numbers
    Feuille 18
    Tableau 12
    4
    D4
    E4
    D8
    E8
    D4
    E4
    D8
    E8
    line1 is the path to the folder containing the source document
    line2 is the name of the source document
    line3 is the name of the source sheet
    line4 is the name of the source table
    line5 is the path to the folder containing the destination document
    line6 is the name of the destination document
    line7 is the name of the destination sheet
    line8 is the name of the destination table
    line9 is the number of values to grab/insert
    then are the references of the source cells
    then are the references to the destination cells
    Footer colNum may be used as a reference to the bottom cell of the column colnum.
    You may use the word 'Footer' or it's localized version ('Pied de page' for instance)
    --=====
    The Finder's Help explains:
    To make the Script menu appear:
    Open the AppleScript utility located in Applications/AppleScript.
    Select the "Show Script Menu in menu bar" checkbox.
    +++++++
    Yvan KOENIG (Vallauris FRANCE)
    23 avril 2009
    24 avril 2009
    on run
    if my parleAnglais() then
    set leFichier to choose file with prompt "Select the parameters text file…" of type {"public.plain-text"}
    else
    set leFichier to choose file with prompt "Choisir un fichier texte contenant les paramètres …" of type {"public.plain-text"}
    end if
    Ugly workaround to grab the localized string "Footer"
    In Numbers it's available in a .nib file in which we can't enter.
    set p2lproj to (path to applications folder as text) & "iWork '09:Pages.app:Contents:Resources:Templates:Woodland Resume.template:Contents:Resources:"
    tell application "Pages" to set FOOTER_loc to localized string "STYLE_Footer" from table "Localizable" in bundle file p2lproj
    try
    set enTexte to paragraphs of (read leFichier from 1)
    set p2source to item 1 of enTexte
    set document1 to item 2 of enTexte
    set sheetSource to item 3 of enTexte
    set tableSource to item 4 of enTexte
    set pDocument1 to p2source & document1
    set p2dest to item 5 of enTexte
    set document2 to item 6 of enTexte
    set sheetDest to item 7 of enTexte
    set tableDest to item 8 of enTexte
    set pDocument2 to p2dest & document2
    set nbRefs to item 9 of enTexte
    set listeSource to items 10 thru (10 - 1 + nbRefs) of enTexte
    set listeDestination to items (10 + nbRefs) thru (10 - 1 + nbRefs + nbRefs) of enTexte
    on error
    if my parleAnglais() then
    error "The text file doesn‘t match the script‘s requirements !"
    else
    error "Le fichier texte ne respecte pas" & return & "les exigences du script !"
    end if
    end try
    tell application "Numbers"
    open pDocument1
    open pDocument2
    grab every wanted values from the source document
    tell document document1 to tell sheet sheetSource to tell table tableSource
    set listeValues to {}
    repeat with aRef in listeSource
    if (aRef starts with FOOTER_loc) or (aRef starts with "footer") then
    copy value of cell (count of rows) of column ((last word of aRef) as integer) to end of listeValues
    else
    copy value of cell aRef to end of listeValues
    end if
    end repeat
    end tell -- document1
    Insert the grabbed values in the destination document
    tell document document2 to tell sheet sheetDest to tell table tableDest
    repeat with i from 1 to count of listeDestination
    set value of cell (item i of listeDestination) to item i of listeValues
    end repeat
    end tell -- document2
    save document document1
    save document document2
    You may disable these two 'closing' lines if you wish to keep the documents open.
    It may be useful if you make changes in the source document and share them with the destination one.
    --close document document1 without saving
    --close document document2 without saving
    end tell -- Numbers
    end run
    --=====
    on parleAnglais()
    local z
    try
    tell application "Numbers" to set z to localized string "Cancel"
    on error
    set z to "Cancel"
    end try
    return (z is not "Annuler")
    end parleAnglais
    --=====
    --[/SCRIPT]
    Yvan KOENIG (from FRANCE vendredi 24 avril 2009 11:08:30)

  • Difference between two files

    Hi, I need to find difference between two files.
    This is an example:
    oldfile.txt:
    This is the old file.
    I need some help with
    this task!.
    newfile.txt:
    This is the new file.
    I need help with this task please!.
    Differences:
    * old -> new
    * need -> need
    * "some" was deleted
    * please was added
    Notice that I don't care spaces, new lines or tabs.
    The code should looks like:
    enum DifferenceType { Added, Deleted, Replaced };
    class DiffText {
      public String Text;
      public DifferenceType Type;
      public String ReplacedText;
      Diff d = new Diff("oldfile.txt","newfile.txt");
      while(!d.end()) {
        DiffText dtext = d.getNext();
       String s = "";
        switch(s.Type) {
          case Added:       System.out.println(s.Text + " ~ added");
          case Deleted:    System.out.println(s.Text + " ~ deleted");
          case Replaced: System.out.println(s.Text + " replaced by " + s.ReplacedText);
      }Thanks for your help in advance.

    Suppose you have two arrays filled with integers.
    What you want to do is map the integers from one
    array to the other.
    In your example, your arrays would look like:
    this is the old file i need some help with this task
    [0 1 2 3 4 5 6 7 8 9 0 10]
    this is the new file i need help with this task please
    [0 1 2 11 4 5 6 8 9 0 10 12]
    Here, I've assumed you've removed all punctuation and
    new line characters, and changed to lowercase.
    The easiest way is to walk through the arrays greedily.
    However, you may be able to research algorithms that
    do a better job of matching.

  • How do I share music between two accounts on the same i-mac

    How do I share music between two accounts on the same i-mac

    iTunes: How to share music between different accounts on a single computer - http://support.apple.com/kb/HT1203 - relocating iTunes' media folder to a shared area but leaving separate library files - extra tip at https://discussions.apple.com/message/17331189

  • How can I share data between two forms on different lists

    Using a custom content type, I created two lists that I want to share the same data - one is a calendar.  Our employees complete a form from the "Out of Office Request" list that has workflow functionality that sends an email to that person's
    manager.  If the manager approves the request, the item automatically populates the "Out of Office Calendar."  The problem is that the only information from the request list that populates the calendar is the Title field and date/time fields. 
    I need the manager name in order to create a view for each manager.  
    How can I connect the other information in the request list to the calendar list.  It seems to me that if the title and date fields carry over the information, there should be a way to connect the other information.  I'm using Designer.
    I've tried to connect the two lists' webparts with the wizard, but when I get to the page that maps the two lists, there are no column names and the "Next >" button is grayed out.  This seems like the logical place to connect the two lists,
    but it isn't working.

    Hi,
    According to your post, my understanding is that you wanted share data between two forms on different lists.
    To show external  information on the calendar event, there are two methods: Calculated column, workflow. You can refer to:
    A Simple Guide to Show More Information on a Calendar Event
    I recommend to use workflow to achieve what you want. But you need to create a people column to display the manager.
    You can create a workflow associated to the "Out of Office Request" list, add action to Start Approve Process. If the manager approves the request, you can create a item in the calendar, and then update the people column and the title column.
    Then the calendar will display the Title, date/time and the manager.
    To create a view for each manager, you need to modify the Filter. You can use the people column is equal to the manager name or the Title contains the manager name.
    Thank you for your understanding.
    Best Regards,
    Linda Li
    Linda Li
    TechNet Community Support

  • How can I share calendars between two different people?

    I am trying to share my ICAL with my wife and she wants to do the same with me. For some reason I cannot find the path to allow us to see each otjer's calendars. Any ideas?
    Thanks
    Don

    Hi,
    According to your post, my understanding is that you wanted share data between two forms on different lists.
    To show external  information on the calendar event, there are two methods: Calculated column, workflow. You can refer to:
    A Simple Guide to Show More Information on a Calendar Event
    I recommend to use workflow to achieve what you want. But you need to create a people column to display the manager.
    You can create a workflow associated to the "Out of Office Request" list, add action to Start Approve Process. If the manager approves the request, you can create a item in the calendar, and then update the people column and the title column.
    Then the calendar will display the Title, date/time and the manager.
    To create a view for each manager, you need to modify the Filter. You can use the people column is equal to the manager name or the Title contains the manager name.
    Thank you for your understanding.
    Best Regards,
    Linda Li
    Linda Li
    TechNet Community Support

  • Share bandwidth between two subinterface

    dears
    I have 2 subinterface (f0/1.100 & f0/1.101)
    and i have 10 Mb BW
    how to share bandwidth between two subinterface ???

    How do you want to share the bandwidth?
    What device and IOS version?

  • Is there any way to share music between two iPhones ?

    I want to share music between two iPhones with different apple IDs , isn't there any method to do that without itunes ?

    In general, the catalog that is open when you do Export As Catalog is where the settings are, and the catalog that is open when you do Import From Catalog is where the settings aren't, yet, but will be after the Import.  Your assumptions appear to be correct for your particular example.

  • How to share documents between two macs,

    I NEED TO SHARE documents between two macs....keynote dcts.....and I always want to be working with the last dct, what is the esiest and safer way to do it ?

    Ok I have three macs sharing mobile me. One at work that´s a imac,at home my old Mack book Pro with a big monitor and now I got a beautiful Mac Book Air.
    The two computers at home can be connected wireless,I have a time capsule disk that at this moment is only backing up my MBPro. I will use my MBA for everyday use,mails,navigating and for lecturing....with keynote. Basically the documents that I need to share daily will be keynote dcts. And may be some apperture projects.
    All the mails calendars etc work beautiful with mobileme.
    I don´t really need to conect the imac at work.
    Any ideas to make things easy?
    If I work only wit dcts does are about 400 KB. If I use my folder of preentations is about 42 GB, I think I just need to work with dcts....

  • TS2972 How can I share playlists between two users on the same laptop?

    I have a work account and a home account on my laptop in Windows 7.  After the new version of iTunes was released this week, I"m unable to share playlists between the two accounts.  HELP.

    iTunes: How to share music between different accounts on a single computer - http://support.apple.com/kb/HT1203 - relocating iTunes' media folder to a shared area but leaving separate library files - extra tip at https://discussions.apple.com/message/17331189

  • API for tools that show differences  between two file in applet

    I am searching Api for tools that show differences between two data file
    that represent as bytes[] in the memory in applet .
    the applet is not sign Applet.

    I gotta it.
    File f=new File("\\\\"+"Linshuaibing"+"\\card\\DSC00134.jpg");[Thank you very much v!

  • [solved] Difference Between Two Files

    Okay, so I have been trying to use diff to do this, but I am failing, as this isn't code I am looking at (and I'm not really a programmer).
    I have two text files with a single line per entry (which is a userid).  I need to be able to compare the two files, and output only the userid's that don't show up in one of the files.
    Example:
    File 1                File 2
    a                      a
    b                      s
    c                      c
    d                      t
    So the output would be simply s and t. 
    Can I use diff to do this?  If not, can someone maybe hack up a quick Perl script or something?  I know there has to be a better way than going through a 2000+ userid file by hand.
    Thanks!
    Last edited by lifeafter2am (2010-08-27 16:19:53)

    yes, use comm.
    but just for fun:
    //blue/0/~/ cat file1
    a
    b
    c
    d
    //blue/0/~/ cat file2
    a
    s
    c
    t
    //blue/0/~/ grep -Fxv "$(< file1)" file2
    s
    t

  • Can i share music between two iTunes accounts on the same computer

    I know you can share the library with 'home share', but can you copy the titles to the account sothey can be loaded on to an ipod / iphone?
    Or have i got to load any required music on to the computer a second time?

    This should help:
    iTunes: How to share music between different accounts on a single computer
    Note that when it says "publicly accessible location", it needs to be a place where everyone has read and write access. The most common such place is the Shared folder in the Users folder, but you can place the music elsewhere if you change the access permissions manually (don't start tinkering with permissions unless you're confident you know what you're doing and can reverse things if they get messed up). 
    Regards.

  • How do i share music between two iphone 4s , but not downloaded apps ?

    i am trying to sync mine & my partners phones so that we can share itunes between both phones, i have set up 1 itunes account (using my apple id) & we each have a icloud account, i have managed to get the music to appear on both phones but it also brought all of my apps onto my partners phone, i think this must be because the itune account is in my apple id, is there a way to share music only ?
    Also to play all the music that is on itunes library on the computer, on my partners phone, you have to change his shared music library setting everytime you wish to see all that is on the itunes account, is this correct?
    hope you can help,

    make 2 user accounts on the computer
    move the music to a folder shared between the 2 accounts
    add the music to itunes on each user account
    sync
    and thats it

  • HT204053 share music between two separate libraries?

    Can you share music from two seperate iTunes Library's? If so please can someone explain how you do that

    http://support.apple.com/kb/ht1449

Maybe you are looking for

  • IPod keeps reseting and is not recognized by my computer

    I plug in my ipod and the copmuter tells me that the disk is not recognized and gives the options of initializing, ignoring, or reseting. And then when I unplug it, the iPod just turns on and off showing the apple logo. Any help would be appreciated.

  • MacBook Pro won't allow me to copy/unrar .RAR Files (error code -36).

    So basically, I've been downloading a lot of .RAR files and its been fine until now. I can't copy/unrar anything. I tried so much I even upgraded from snowy leopard to Lion. I'm pretty angry and I've tried dot_clean /users/manraj/desktop/ I've reform

  • XI3.0: SOAP-Adapter Exception

    Hi All, I'm trying to send a message to a web service via the SOAP adapter. Unfortunately the SOAP adapter throws the following exception: <i> SOAP: error occured: com.sap.aii.messaging.srt.BubbleException: Failed to call the endpoint: HTTP 0 null [n

  • Updating GUI after JFileChooser choice made.

    Hello, I'm trying to enable a button on the GUI that launched the JFileChooser to become enabled if an appropriate file was selected. I can set a variable to true if 'open' was clicked. I can set a variable to false if 'cancel' was clicked. I can get

  • Looking for plugin

    Hi, I'm looking for a plugin that can automatic sees an .xml file from the server, place the .xml in a stylesheet and save this as a .pdf file on the server. If possible with a demo version. If anyone know a plugin that can do this, please let me now