Protocol Declaration Problem

Discussion in 'iOS Programming' started by iLoveDeveloping, Mar 16, 2010.

  1. iLoveDeveloping macrumors regular

    Joined:
    Sep 24, 2009
    Location:
    Ireland
    #1
    Hey,

    I'm trying to get a new view in my app to work, but I'm getting an error when i run it!

    I went to the documentation and seen this,

    But, i have no idea how to write this in the app?! Someone said i might need to create an instance for SubstitutableViewController but im not sure what it is i have to do exactly? Anyone have any answers? Or example of what this should look like?


    Thanks for any help...
     
  2. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    A protocol declaration is a lot like a class declaration. There are also a bunch of them in the Apple headers. Look at those and model yours after one of them.

    Typically it goes into a header file after the class declaration of the class that is related to it. You usually have a forward declaration before that class declaration because it needs to see the protocol declaration in order to declare its delegate. If you like the protocol declaration can go before the class declaration in the header file. Then any classes that need to know about the protocol declaration will import that header.

    Open the multiple find window in Xcode. Type @protocol in the Find box. Choose 'In Frameworks' and click Find. You'll see over 20 examples.
     
  3. iLoveDeveloping thread starter macrumors regular

    Joined:
    Sep 24, 2009
    Location:
    Ireland
    #3

    Ok i put in "@protocol SubstitutableViewController;" and the app launches, but it crashes right away.. I looked in the console and it is saying:

    What does this mean? It is looking for the dataSource for the table view?
     
  4. drf1229 macrumors regular

    drf1229

    Joined:
    Jun 22, 2009
    #4
    Seems to be so. What dataSource is your UITableView is connected to? Can you please describe your project in a bit more detail? Seems like your protocol issue is fixed though.
     
  5. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #5
    That error just means that the cell returned from cellForRowAtIndexPath: was a nil pointer.
     
  6. iLoveDeveloping thread starter macrumors regular

    Joined:
    Sep 24, 2009
    Location:
    Ireland
    #6
    So can i fix that? Or are you saying thats not what is crashing it?
     
  7. drf1229 macrumors regular

    drf1229

    Joined:
    Jun 22, 2009
    #7
    It can be fixed, it means when you the cellForRowAtIndexPath, the cell returned is nil. How is cellForRowAtIndexPath declared in your project?
     
  8. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #8
    Your cellForRowAtIndexPath method has a bug. It is returning nil when it should be returning a valid cell. Show your code for this method.
     

Share This Page