Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7893159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:03:30+00:00 2026-06-03T07:03:30+00:00

Ok, so am kind of new to programming for iPhones and Objective C and

  • 0

Ok, so am kind of new to programming for iPhones and Objective C and Cocoa Touch, but cannot figure this out. There is a lot of information when the delegate is self, but I am trying to send it to another file.

Here is some code…
I have the following method (I would normally call it a function but I think method is the correct terminology) in appDelegate.m

[GameUtil showAlertViewWithTag:1 delegate:self withTitle:@"" message:msg cancelButtonTitle:@"New game" otherButtonTitles:@"Main Menu", nil];

In GameUtil.h and .m I have showAlertViewWithTag set up properly and it is working fine.

The problem I am having, is with the delegate:self part … as it stands, when a button on alertview is clicked, it will go to -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex that is located in my appDelegate.m(which of course is expected when using self as the delegate).

But what I want it to do when a button is clicked is send it to -(void)alertView:.. in a different file called playField.m.

I have the alertview setup correctly in playField.m (have tested by calling alertview with delegate:self from within playField.m).

Basically I am stumped on how to tell the alertview in appDelegate.m to use a delegate that is in playField.m instead of delegate:self.

I think I need to #import playField.m or .h at into appDelegate.m but beyond that I am lost with all the @protocol @interface stuff.

Baby steps would be very helpful, like “You need to put XYZ at the top of your playField.h and ABC at the top of playField.m”.

I am hoping this is fairly simple to implement, and that I am just missing a few simple things.

Thanks in advance 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:03:32+00:00Added an answer on June 3, 2026 at 7:03 am

    First, even though the outcome of this is going to be that the delegate method will be in another file, you should rather think of it as “the delegate is another object”.
    In your case, the delegate object is self, that is the App Delegate object. (because you’re writing this inside the app delegate implementation)

    In order for the delegate to be another object, you first need to have an instance of that object accessible in your app delegate.

    I am assuming your playField files hold a playField class. (I would have called it PlayField btw, classes are usually capitalized, and the objects (an instance of a class) are not, although it works either way.

    Somewhere, you need to instantiate a playField object, have you done that somewhere? This would look like:

    playField *pf=[[playField alloc] init];
    

    If you haven’t done so, then do it above the showAlertViewCode.
    In order for the classes to be available in your appDelegate, add:

    #import "playField.h"
    

    on top of your appDelegate file.

    then in your alertview code, replace self by the object you just created:

    [GameUtil showAlertViewWithTag:1 delegate:pf withTitle:@"" message:msg cancelButtonTitle:@"New game" otherButtonTitles:@"Main Menu", nil];
    

    Now your delegate is the pf Object, which is an instance of playField, therefore the delegate method will be called from your playField.m implementation file.

    Hope this makes sense!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a kind of a newb question but I'm really new to programming
I am kind of new to programming but I already do know a lot.
i'm new to this kind of things. Kinda the first post ever regarding programming,
Hey guys, sorry I'm kind of new to programming, but I had a small
I'm kind of new to this site and programming in general, so please excuse
I am not new to programming, but kind of rusty in Javascript/web development. I
I'm kind of new to C, but not to programming. I'm trying to create
im new to programming in Objective C and really even to programming kind of.
I am kind of new to C# and Asp.Net, so this question might sound
So I'm kind of new to this, I'm writing a WIN32 app that records

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.