Results 1 to 2 of 2
Discuss UITableViewCell image update in one cell mistakenly automatically gets to other cells at the iPhone Developer Exchange - Hackint0sh.org; Hi, Am a newbie to iOS programming (but I've done my homework ... going through ...
  1. #1
    Newbie Array

    Join Date
    Apr 2012
    Posts
    1
    Post Thanks / Like
    Downloads
    0
    Uploads
    0
    Rep Power
    0

    Question UITableViewCell image update in one cell mistakenly automatically gets to other cells

    Hi, Am a newbie to iOS programming (but I've done my homework ... going through books on iOS and google tutorials). Am trying to do this:

    1. User inputs some text in a text field, & chooses an emoticon.

    2. I then add the user-input-text to a UITableViewCell and add the cell to the UITableView.



    THE PROBLEM

    > Say, the user enters some text and chooses the 'happy' emoticon.

    > The emoticon and text get updated in the UITableView. No problem with this.

    > Next, the user enters some other text, and chooses the 'sad' emoticon.

    > The problem is:
    The emoticon in the previous cell (where it's a happy emoticon) also changes to 'sad'; but,I don't want the previous cell's emoticon to change. The previous one has to remain the 'happy' emoticon, and that in the 2nd cell has to be 'sad', b'cos that's what the user chose.


    @synthesize table;
    @synthesize buttonEmotionHappy;
    @synthesize buttonEmotionLaugh;

    int myEmoticonNum;

    /**
    * Called when the button's pressed
    * sender : the button which's pressed, consequently invoking this
    */
    -(IBAction)buttonPressedid)sender {

    NSLog(@"Button Pressed");
    [self addToInputArray:[textFieldUserInput text]];

    [table reloadData];
    textFieldUserInput.text = @"";
    }


    -(IBAction)emotionExpressedid)sender {

    if (sender == buttonEmotionHappy) {

    NSLog(@"Happy emoticon chosen");
    myEmoticonNum = 1;

    } else if (sender == buttonEmotionSad) {

    NSLog(@"Sad emoticon chosen");
    myEmoticonNum = 2;
    }
    }

    ...
    ...
    ...
    ...
    #pragma mark -
    #pragma mark Table View Data Source Methods

    -(NSInteger) tableViewUITableView *)tableView numberOfRowsInSectionNSInteger)section {
    return [self.arrayInput count];
    }


    -(UITableViewCell *) tableViewUITableView *)tableView
    cellForRowAtIndexPathNSIndexPath *)indexPath {

    static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdent ifier];

    if (cell == nil) {

    cell = [[UITableViewCell alloc]
    initWithStyle:UITableViewCellStyleDefault
    reuseIdentifier:SimpleTableIdentifier];
    }


    if (myEmotionNum == 1) {
    cell.imageView.image = [UIImage imageNamed:@"SmileyHappy.png"];

    } else if (myEmotionNum == 2) {
    cell.imageView.image = [UIImage imageNamed:@"SmileySad.png"];
    }

    NSUInteger row = [indexPath row];
    cell.textLabel.text = [arrayInput objectAtIndex:row];

    return cell;
    }

    -(void) addToInputArray: (NSString *)userInput {

    [arrayInput insertObject:userInput atIndex:0];
    NSLog(@"Added %@ to User-Input-Array", userInput);
    }



    Thanks,
    Priya


  2. #2
    Newbie Array

    Join Date
    Sep 2008
    Posts
    3
    Post Thanks / Like
    Downloads
    0
    Uploads
    0
    Rep Power
    0

    Default

    You should be basing which emoticon to show off of the indexPath.row, just like you're doing with the text.

 

 

Similar Threads

  1. Replies: 0
    Last Post: 09-27-2009, 10:03 PM
  2. MacNN: Sprint to have unlimited cell-to-cell with any network?
    By hackint0sh in forum Latest Headlines
    Replies: 0
    Last Post: 09-10-2009, 05:10 AM
  3. [1.1.3] Where is the Soft Update image to delete ?
    By meatwagon in forum iPhone "2G" (Rev. 1)
    Replies: 3
    Last Post: 01-28-2008, 11:19 AM
  4. Replies: 0
    Last Post: 11-21-2007, 11:07 AM
  5. Do iTunes the 1.1.1 Update automatically?
    By fatal in forum General
    Replies: 2
    Last Post: 09-30-2007, 07:27 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Powered by vBulletin®
Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.
Search Engine Friendly URLs by vBSEO
(c) 2006-2012 Hackint0sh.org
All times are GMT +2. The time now is 04:28 PM.
twitter, follow us!