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 7691305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:35:33+00:00 2026-05-31T20:35:33+00:00

I know the ARC in iOS 5 but I’m now developing pre-iOS 5 code

  • 0

I know the ARC in iOS 5 but I’m now developing pre-iOS 5 code style, and want to solve this problem by a manual release approach.

My only goal for this is to make a very handy custom alert view with UITextField.

I have a ‘BigView’ view that has many functions in it. And it can possibly generate many UIAlertView for many different situation on the display with that view. So I know the way use UIAlertViewDelegate for each alert view, but kind of experimentally try want to make this as like UIButton’s ‘addTarget'(actually it’s UIControl’s method).

Briefly,

This is in the part of ‘BigView’ class and my ‘TextAlert’ instance fired by a button for email gathering .

BigView.m

- (void)emailFeedback:(id)sender
{
    TextAlert *textAlert = [[TextAlert alloc] initWithTitle:@"Enter your email address"];
    [textAlert setTarget:self action:@selector(textAlertInputed:)];
//    [textAlert release];
}

- (void)textAlertInputed:(NSString *)text
{
    NSLog(@"text alert inputed, text: %@", text);
}

and these are full my TextAlert files.

TextAlert.h

#import <Foundation/Foundation.h>

@interface TextAlert : NSObject <UIAlertViewDelegate>
{
    UIAlertView *alertView;
    UITextField *textField;
    id target;
    SEL action;
}

- (id)initWithTitle:(NSString *)title;
- (void)setTarget:(id)target action:(SEL)action;

@end

TextAlert.m

#import "TextAlert.h"

@implementation TextAlert

- (id)initWithTitle:(NSString *)title
{
    if (self = [super init]) 
    {
        alertView = [[UIAlertView alloc] initWithTitle:title message:@"beneath" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
        textField = [[UITextField alloc] initWithFrame:CGRectMake(12, 45, 260, 25)];
        CGAffineTransform myTransform = CGAffineTransformMakeTranslation(0, 60);
        [alertView setTransform:myTransform];
        [textField setBackgroundColor:[UIColor whiteColor]];
        [alertView addSubview:textField];
        [alertView show];

    }
    return self;
}

- (void)dealloc
{
    [alertView release]; alertView = nil;
    [textField release]; textField = nil;
    [super dealloc];
}

- (void)setTarget:(id)_target action:(SEL)_action
{
    target = _target;
    action = _action;
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    [target performSelector:action withObject:textField.text];
}

@end

So my main problem is the releasing point of TextAlert instance in the ‘BigView’ as you can see the only comment part full codes above. Of course if I remove that comment out, I got crash for call for method of deallocated.

And I also get error make textAlert instance as autoreleased one.

For me, the only solution for this is to make the ‘textAlert’ object in the ‘BigView’ a member of ‘BigView’ not local object. But in that case, my initial goal for handy and lightweight approach for this is not satisfied, I think. And the ‘BigView’ has already many member instances so I don’t want to add any more.

So any suggestions? Or It will be welcome any comment for this trying. I’m ready to hear any
reproves to my insufficient code, really.

Thanks in advance,

MK

  • 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-05-31T20:35:34+00:00Added an answer on May 31, 2026 at 8:35 pm

    This isn’t directly what you asked for, but could help you anyway.

    Handling multiple UIAlertViews in a single UIViewController can be painful. When I ran into this problem, I found an alternative control on github, called BlockAlertsAndActionSheets. It uses blocks instead of delegates, the appearance can be fully customized (even to the default Apple-style) and there is also an “AlertView with an UITextField”. Works good for me and I didn’t have to reinvent that wheel! 😉

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

Sidebar

Related Questions

I'm attempting to solve the Code Golf: Build Me an Arc problem. My solution's
I have been using XCode 3.2.4 when started developing iOS apps but now I
Know this might be rather basic, but I been trying to figure out how
I know this might be a no-brainer, but please read on. I also know
I want to use CocosDenshion with my ARC enabled project but when I simply
I'm making a static library product. I want to use ARC but one of
I'm trying to migrate to ARC but I get this error, i really don't
I know that this question had been asked many times, but every answer seems
I have an iOS app that I want to convert to using ARC .
This is about ARC in IOS 5. Suppose it is ARC enabled and I

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.