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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:37:29+00:00 2026-06-14T01:37:29+00:00

In my view i have one UIimageview and 4 UIButton , I show the

  • 0

In my view i have one UIimageview and 4 UIButton , I show the images from NSMutableArray. How can i show the UIButton title as imageview images name without .png?I tried with following coding

imageary=[[NSMutableArray alloc]initWithObjects:[UIImage imageNamed:@"dear.jpg"],[UIImage imageNamed:@"donkey.jpg"],[UIImage imageNamed:@"elephant.jpg"],[UIImage imageNamed:@"fox.jpg"],[UIImage imageNamed:@"giraffe.jpg"],[UIImage imageNamed:@"goat.jpg"],[UIImage imageNamed:@"buffallo.jpg"],[UIImage imageNamed:@"bull.jpg"],[UIImage imageNamed:@"cow.jpg"],[UIImage imageNamed:@"crocodile.jpg"], nil];


 - (NSString *) convertToDisplayName:(NSString *)actual
{
return [actual stringByReplacingOccurrencesOfString:@".png" withString:@" "];

}

While trying to retrive name using the above method

int i=0;
for(UIView *view in self.view.subviews)
{
    if([view isKindOfClass:[UIButton class]])
    {
       mybutton = (UIButton *)view;
        if(mybutton.tag == 1||mybutton.tag == 2||mybutton.tag == 3||mybutton.tag == 4)
        {

             animage.image=[imageary objectAtIndex:i];
            name=[self convertToDisplayName:[imageary objectAtIndex:i]];
            [mybutton setTitle:name forState:UIControlStateNormal];
            NSLog(@"current image name :%@",name);
            i++;

        }
    }
   }

it showing error

 Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage stringByReplacingOccurrencesOfString:withString:]: unrecognized selector sent to instance 0x73f8eb0

Please help where i have to correct.

  • 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-14T01:37:31+00:00Added an answer on June 14, 2026 at 1:37 am

    You are passing UIImage object in that function where as You should maintain the array of image names and pass that image name in this function & by the way you can simply get the name by removing extension by using this method:

    [actual stringByDeletingPathExtension];
    

    Here’s what you should do

    imageary=[[NSMutableArray alloc]initWithObjects:@"dear.jpg",@"donkey.jpg",@"elephant.jpg",@"fox.jpg",@"giraffe.jpg",@"goat.jpg",@"buffallo.jpg",@"bull.jpg",@"cow.jpg",@"crocodile.jpg", nil]; // declare array of names not images
     - (NSString *) convertToDisplayName:(NSString *)actual
    {
      return [actual stringByDeletingPathExtension]; //return image name without extension
    }
    

    Than this

    int i=0;
    for(UIView *view in self.view.subviews)
    {
    if([view isKindOfClass:[UIButton class]])
    {
       mybutton = (UIButton *)view;
        if(mybutton.tag == 1||mybutton.tag == 2||mybutton.tag == 3||mybutton.tag == 4)
        {
             i = rand() % [imageary count]; // set random image
             animage.image=[UIImage imageNamed:[imageary objectAtIndex:i]]; // return image with this name
            name=[self convertToDisplayName:[imageary objectAtIndex:i]];
            [mybutton setTitle:name forState:UIControlStateNormal];
            NSLog(@"current image name :%@",name);
            i++;
    
        }
    }
    }
    

    Hope that helps!

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

Sidebar

Related Questions

I have 8 images in the array and UIImageView that displays one image from
I have two UIImageView objects inside my view (both 320x480 one above the other).
I have one view controller in which I have added UIScrollView & UIImageView programatically.
I have a simple display with one UIImageView, two UIButton, and two UILabel. UIImageview
I have two overlay images that I want show in camera view depending on
In one UIVIew i have 5 icon (UIImageView). I show/hide icons. Its ok. But
I have one view in iPhone application. In that view i added two UIImageView
I have an UIImageView object in one of my viewController view that is preloaded
How would I have one view up when the iPhone is in a standard
suppose I have a model and a view ,ths view have two method:one is

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.