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 ...
-
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)buttonPressed
id)sender {
NSLog(@"Button Pressed");
[self addToInputArray:[textFieldUserInput text]];
[table reloadData];
textFieldUserInput.text = @"";
}
-(IBAction)emotionExpressed
id)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) tableView
UITableView *)tableView numberOfRowsInSection
NSInteger)section {
return [self.arrayInput count];
}
-(UITableViewCell *) tableView
UITableView *)tableView
cellForRowAtIndexPath
NSIndexPath *)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
-
-
You should be basing which emoticon to show off of the indexPath.row, just like you're doing with the text.
-
Similar Threads
-
By wim in forum AppleTV 1
Replies: 0
Last Post: 09-27-2009, 10:03 PM
-
By hackint0sh in forum Latest Headlines
Replies: 0
Last Post: 09-10-2009, 05:10 AM
-
By meatwagon in forum iPhone "2G" (Rev. 1)
Replies: 3
Last Post: 01-28-2008, 11:19 AM
-
By geuis dassin in forum General
Replies: 0
Last Post: 11-21-2007, 11:07 AM
-
By fatal in forum General
Replies: 2
Last Post: 09-30-2007, 07:27 PM
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks