How do we show a table view inside a UIAlertView - ios

I am trying to add a UITableView inside my UIAlertView and its not showing up. I just see title & message along with "OK" button on alertview.
Below is my code and I am running on iOS 7.
- (void)showDataReceivedAlert {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Received Data" message:#"\n\n\n\n\n\n\n\n\n\n\n\n" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
UITableView *table = [[UITableView alloc]initWithFrame:CGRectMake(10, 40, 264, 120)];
table.delegate = self;
table.dataSource = self;
table.backgroundColor = [UIColor clearColor];
[alert addSubview:table];
[alert show];
}
- (NSInteger)tableView:(UITableView *)iTableView numberOfRowsInSection:(NSInteger)iSection {
return 6;
}
- (UITableViewCell *)tableView:(UITableView *)iTableView cellForRowAtIndexPath:(NSIndexPath *)iIndexPath {
static NSString *identifier = #"iBeaconDataCell";
UITableViewCell *cell = [iTableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryNone;
}
NSString *cellText;
NSString *cellLabelText;
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSData *encodedObject = [userDefaults objectForKey:#"data"];
MyObj *myData = (MyObj *)[NSKeyedUnarchiver unarchiveObjectWithData:encodedObject];
switch (iIndexPath.row) {
case 0:
cellText = #"Data 1";
cellLabelText = [NSString stringWithFormat:#"%d", myData.data1];
break;
case 1:
cellText = #"Data 2";
cellLabelText = [NSString stringWithFormat:#"%d", myData.data2];
break;
case 2:
cellText = #"Data 3";
cellLabelText = [NSString stringWithFormat:#"%d", myData.data3];
break;
case 3:
cellText = #"Data 4";
cellLabelText = [NSString stringWithFormat:#"%d", myData.data4];
break;
case 4:
cellText = #"Data 5";
cellLabelText = [NSString stringWithFormat:#"%f", myData.data5];
break;
case 5:
cellText = #"Data 6";
cellLabelText = myData.data6;
break;
default:
break;
}
cell.textLabel.text = cellText;
UILabel *cellLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 150.0, 44.0)];
cellLabel.text = cellLabelText;
cell.accessoryView = cellLabel;
return cell;
}

The default alert isn't meant to take subviews. (while in ios6 and earlier add. subviews could be hacked in, this does NOT work in iOS7)
write your own custom UIView that looks and acts like an alert.
There's a lot of implementations around if you prefer not to do it yourself :) e.g. on cocoacontrols.com

From iOS 7 you need to add like this
[alertview setValue:tableView forKey:#"accessoryView"];

Related

Dynamic UITableview with different objects

I have a tableview with custom cells with UITextField, UIDatePicker, UIPickerView.
In my method cellForRowAtIndexPath I set for every row its behavior.
But I realized that when I hit the first rows at the top everything is fine, instead when I scroll down the table and change the values on the bottom for example the value I entered on line 7 is inserted on line 8 and so on in the lower lines
in practice it creates confusion with the index of the lines when I scroll the table
or for example il UITableViewCellAccessoryDisclosureIndicator instead of assigning it to line 9 when reloading the table, the table assigns it to line 2
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell" forIndexPath:indexPath];
UITextField *text1 = (UITextField *)[cell viewWithTag:100];
UILabel *text2 = (UILabel *)[cell viewWithTag:200];
text1.text = [valuesArray objectAtIndex:indexPath.row];
text2.text = [titlesArray objectAtIndex:indexPath.row];
switch (indexPath.row) {
case 0:
{
text1.delegate = self;
text1.tag = indexPath.row;
}
break;
case 1:
{
activityPicker = [[UIPickerView alloc] init];
activityPicker.delegate = self;
activityPicker.tag = indexPath.row;
text1.delegate = self;
text1.inputView = activityPicker;
}
break;
case 2:
{
datePicker = [[UIDatePicker alloc] init];
datePicker.datePickerMode = UIDatePickerModeDate;
[datePicker addTarget:self action:#selector(onDatePickerValueChanged:) forControlEvents:UIControlEventValueChanged];
text1.delegate = self;
text1.inputView = datePicker;
datePicker.tag = indexPath.row;
}
break;
case 3:
{
datePicker = [[UIDatePicker alloc] init];
datePicker.datePickerMode = UIDatePickerModeTime;
[datePicker addTarget:self action:#selector(onDatePickerValueChanged:) forControlEvents:UIControlEventValueChanged];
text1.delegate = self;
text1.inputView = datePicker;
datePicker.tag = indexPath.row;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:#"HH:mm"];
[datePicker setDate: [dateFormatter dateFromString:text1.text]];
}
break;
case 4:
{
activityPicker = [[UIPickerView alloc] init];
activityPicker.delegate = self;
activityPicker.tag = indexPath.row;
NSString *km = [text1.text substringToIndex:[text1.text length]-3];
int numkm = [km intValue] - 1;
[activityPicker selectRow:numkm inComponent:0 animated:YES];
text1.delegate = self;
text1.inputView = activityPicker;
}
break;
case 5:
{
activityPicker = [[UIPickerView alloc] init];
activityPicker.delegate = self;
activityPicker.tag = indexPath.row;
text1.delegate = self;
text1.inputView = activityPicker;
}
break;
case 6:
{
activityPicker = [[UIPickerView alloc] init];
activityPicker.delegate = self;
activityPicker.tag = indexPath.row;
if ([text1.text isEqualToString:[animalsArray objectAtIndex:0]])
[activityPicker selectRow:0 inComponent:0 animated:YES];
else
[activityPicker selectRow:1 inComponent:0 animated:YES];
text1.delegate = self;
text1.inputView = activityPicker;
}
break;
case 7:
text1.delegate = self;
text1.tag = indexPath.row;
}
break;
case 8:
{
activityPicker = [[UIPickerView alloc] init];
activityPicker.delegate = self;
activityPicker.tag = indexPath.row;
if ([text1.text isEqualToString:[privacyArray objectAtIndex:0]])
[activityPicker selectRow:0 inComponent:0 animated:YES];
else
[activityPicker selectRow:1 inComponent:0 animated:YES];
text1.delegate = self;
text1.inputView = activityPicker;
}
break;
case 9:
{
text1.enabled = NO;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
break;
default:
break;
}
return cell;
}
Your problem is using the same cell identifier "Cell" for all rows. This results in cells that you have already configured for a certain row to be reloaded & reused again for another row.
Assuming you have just these 10 cell designs, you could do:
NSString* identifier = [NSString stringWithFormat: #"Cell-%d", indexPath.row];
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:identifier
forIndexPath:indexPath];
In this way, dequeueReusableCellWithIdentifier will only return the cell that was created earlier for the current indexPath.

Issue Displaying Multiple Beacons in TableView

I am trying to display multiple beacons in a tableView. The minor values, name, and images for each beacon are stored in core data. While the name and image of the beacon are appearing in the tableView cell correctly, the proximity always changing to the closest beacon.
I really appreciate the help!
DisplayTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"CellID"];
Tag *tag = [self.tags objectAtIndex:indexPath.row];
cell.textLabel.text = #"";
NSData *data = tag.image;
UIImage *image = [UIImage imageWithData:data];
cell.imageView.image = image; //BEACONS
if (self.tags.count > 0)
{
self.arrow.hidden = true;
self.addLabel.hidden = true;
CLBeacon *beacon = [self.beacons objectAtIndex:indexPath.row];
NSString *proximityLabel = #"";
switch (beacon.proximity)
{
case CLProximityFar:
proximityLabel = [NSString stringWithFormat:#"Your %# is Far", tag.name];
cell.backgroundColor = [UIColor colorWithRed:(255/255.0) green:(107/255.0) blue:(105/255.0) alpha:1];
break;
case CLProximityNear:
proximityLabel = [NSString stringWithFormat:#"Your %# is Near", tag.name];
cell.backgroundColor = [UIColor colorWithRed:(96/255.0) green:(102/255.0) blue:(232/255.0) alpha:1];
break;
case CLProximityImmediate:
proximityLabel = [NSString stringWithFormat:#"Your %# is Close", tag.name];
cell.backgroundColor = [UIColor colorWithRed:(118/255.0) green:(225/255.0) blue:(167/255.0) alpha:1];
break;
case CLProximityUnknown:
proximityLabel = #"Fetching Location";
cell.backgroundColor = [UIColor whiteColor];
break;
}
cell.nameLabel.text = tag.name;
NSString *detailLabel = [NSString stringWithFormat:#"%#, Dist: %0.001f", proximityLabel, beacon.accuracy];
cell.proxLabel.text = detailLabel;
self.tableView.hidden = false;
self.mapView.hidden = false;
}
return cell;
}

Pass UILabel text from UITableViewCell to a different function

I've tried searching around for an answer, but have not succeeded in doing so.
I want to pass the text in one of the UILabel's the cell holds. I am not entirely sure on how to do this. I am trying to pass the content of one of the UILabels into the swipeTableViewCell didTriggerRightUtilityWithIndex function, as I am using SWTableViewCell.
The table is populated with items from a mysql table.
This is my current UITableViewCell function:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #"SimpleTableItem";
if([taskArray valueForKey:#"TaskData"] != [NSNull null])
{
GroupDataTableViewCell *cell = (GroupDataTableViewCell*)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
// Add utility buttons
NSMutableArray *rightUtilityButtons = [NSMutableArray new];
[rightUtilityButtons sw_addUtilityButtonWithColor:
[UIColor colorWithRed:1.0f green:0.231f blue:0.188 alpha:1.0f]
title:#"Les mer"];
cell.rightUtilityButtons = rightUtilityButtons;
cell.delegate = self;
if (cell == nil) {
//cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"SimpleTableItem" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
NSDictionary *item = [taskArray objectAtIndex:indexPath.row];
if([item objectForKey:#"TaskID"] != [NSNull null])
cell.numberTextField.text = [item objectForKey:#"TaskID"];
if([item objectForKey:#"Title"] != [NSNull null])
cell.titleTextField.text = [item objectForKey:#"Title"];
if([item objectForKey:#"Description"] != [NSNull null])
cell.descriptionTextField.text = [item objectForKey:#"Description"];
if([[selfArray valueForKey:#"CheckStat"] isEqualToString:#"(null)"])
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
else if([[selfArray valueForKey:#"CheckStat"] length] == 0)
{
if ([[item objectForKey:#"CheckStat"] containsString:#"1"])
cell.accessoryType = UITableViewCellAccessoryCheckmark;
else
cell.accessoryType = UITableViewCellAccessoryNone;
}
else
{
for(int i = 0; i < [[[selfArray valueForKey:#"CheckStat"] componentsSeparatedByString:#","] count]; i++)
{
NSString *checkedNumStr = [[[selfArray valueForKey:#"CheckStat"] componentsSeparatedByString:#","] objectAtIndex:i];
//if (i >= [taskArray count] || [checkedNumStr intValue] >= [taskArray count])
//break;
if ([checkedNumStr intValue] == indexPath.row + 1)
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
}
return cell;
}
else
return nil;
}
I want to send the cell.descriptionField.text from there to this code, when the rightUtilityButton is activated:
- (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)index {
switch (index) {
case 0:
{
// More button is pressed
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Bookmark" message:#"Description" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alertView show];
[cell hideUtilityButtonsAnimated:YES];
break;
}
case 1:
default:
break;
}
}
So, I want the cell.descriptionTextField.text from the first snippet into the second snippet. I am not entirely sure on how to do this, as I am not good with tablecells. I want the cell.descriptionTextField.text from the first snippet to show up in the alertView as the description.
Save your [item objectForKey:#"Description"] into an NSMutableArray previously created, if you order your cells with the same order as the nsmutablearray, you could access this value into your wanted function like this:
- (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)index {
switch (index) {
case 0:
{
// More button is pressed
NSString *desc = [myarray objectAtIndex:index];
// Use your string wherever you want
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Bookmark" message:#"Description" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alertView show];
[cell hideUtilityButtonsAnimated:YES];
break;
}
case 1:
default:
break;
}
}
Why don't you just store those text in NSString* property within your class and then use wherever you need?
Do not store information in cell object rather than that use datasource to store information.
using index you can get the respective information that was stored in label
In your case you are storing description in label which can be later retrieved as follows
-(void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)index
{
NSDictionary *item = [taskArray objectAtIndex:index;
//Do something with the item
}

GPUImage memory accumulation filtering images into UITableViewCell's UIImageView

I have listed a bunch of GPUImage filters into a UITableView with one filter per UITableViewCell. I am using the UITableViewCell's UIImageView image to show a sample of what the image may look like with that filter.
However, when pop the view that lists the filters, the memory is not cleared. When I open the women again, it accumulates even more memory that doesn't get deallocated. Where could the hangup be that's not deallocated the memory?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger index = [indexPath row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"FilterCell"];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"FilterCell"];
cell.textLabel.textColor = [UIColor blackColor];
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
switch( index )
{
case GPUIMAGE_SATURATION: cell.textLabel.text = #"Saturation"; break;
case GPUIMAGE_CONTRAST: cell.textLabel.text = #"Contrast"; break;
case GPUIMAGE_BRIGHTNESS: cell.textLabel.text = #"Brightness"; break;
case GPUIMAGE_LEVELS: cell.textLabel.text = #"Levels"; break;
case GPUIMAGE_EXPOSURE: cell.textLabel.text = #"Exposure"; break;
case GPUIMAGE_RGB: cell.textLabel.text = #"RGB"; break;
case GPUIMAGE_HUE: cell.textLabel.text = #"Hue"; break;
case GPUIMAGE_WHITEBALANCE: cell.textLabel.text = #"White balance"; break;
case GPUIMAGE_MONOCHROME: cell.textLabel.text = #"Monochrome"; break;
/* More omitted */
}
NSString *identifier = [NSString stringWithFormat:#"%lu", (unsigned long)index];
UIImage *image = imageCache[ identifier ];
if( image )
[[cell imageView] setImage:image];
else
{
// Placeholder image
[[cell imageView] setImage:[UIImage imageNamed:#"Placeholder.png"]];
// if( myTableView.dragging == NO && myTableView.decelerating == NO)
// {
dispatch_async(dispatch_get_main_queue(), ^{
UIImage *image = [self filterPreview:index];
if( !image )
return;
imageCache[ identifier ] = image;
// Make sure the cell is still available
NSIndexPath *myIndexPath = [myTableView indexPathForCell:cell];
if( myIndexPath==nil || myIndexPath.row==indexPath.row )
{
[[cell imageView] setImage:image];
[myTableView beginUpdates];
[myTableView reloadRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationNone];
[myTableView endUpdates];
}
});
// }
}
return( cell );
}
And the function call:
- (UIImage *)filterPreview:(GPUImageShowcaseFilterType)filterType
{
GPUImageOutput<GPUImageInput> *filter;
switch( filterType )
{
case GPUIMAGE_SEPIA:
{
filter = [[GPUImageSepiaFilter alloc] init];
}; break;
case GPUIMAGE_PIXELLATE:
{
filter = [[GPUImagePixellateFilter alloc] init];
}; break;
case GPUIMAGE_POLARPIXELLATE:
{
filter = [[GPUImagePolarPixellateFilter alloc] init];
}; break;
case GPUIMAGE_PIXELLATE_POSITION:
{
filter = [[GPUImagePixellatePositionFilter alloc] init];
}; break;
case GPUIMAGE_POLKADOT:
{
filter = [[GPUImagePolkaDotFilter alloc] init];
}; break;
case GPUIMAGE_HALFTONE:
{
filter = [[GPUImageHalftoneFilter alloc] init];
}; break;
case GPUIMAGE_CROSSHATCH:
{
filter = [[GPUImageCrosshatchFilter alloc] init];
}; break;
case GPUIMAGE_COLORINVERT:
{
filter = [[GPUImageColorInvertFilter alloc] init];
}; break;
case GPUIMAGE_GRAYSCALE:
{
filter = [[GPUImageGrayscaleFilter alloc] init];
}; break;
case GPUIMAGE_MONOCHROME:
{
filter = [[GPUImageMonochromeFilter alloc] init];
[(GPUImageMonochromeFilter *)filter setColor:(GPUVector4){0.0f, 0.0f, 1.0f, 1.f}];
}; break;
/* More of the same omitted */
}
UIImage *returnImage = [filter imageByFilteringImage:sampleImage];
return( returnImage );
}

uitableview reloaddata cache?

I'm having some problems with an UITableView and the method reloadData.
I'm refreshing the tableView when clicking over a refresh button with the last info in a data base ordered descendingly so the most recent items should appear in first position.
Every cell in my tableview is being filled with custom labels and uiimageviews.
Well... the thing is that when I press that refresh button and new data is found, the first 5 rows (which are the ones that are being shown in the display) aren't updated but the following rows do. However, if I press over any of the 5 first rows, they call correctly to the tableView:didSelectRowAtIndexPath: method with the new data.
So, the problem is that the tableview's "visual" content of the first 5 rows is not being updated.
Anyone can help me with this?
Thanks!
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [ NSString stringWithFormat: #"%d:%d", [ indexPath indexAtPosition: 0 ], [ indexPath indexAtPosition:1 ]];
UITableViewCell *cell = [ tableView dequeueReusableCellWithIdentifier: CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame: CGRectZero reuseIdentifier: CellIdentifier] autorelease];
// Configure the cell...
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
Activity *activity = [[self.activities valueForKey:[[[self.activities allKeys] sortedArrayUsingSelector:#selector(localizedCaseInsensitiveCompare:)] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
cell.textLabel.text=#"";
//Mostramos el nombre
UILabel *label= [[UILabel alloc] initWithFrame:CGRectMake(60, -5, 200, 34)];
label.text = [activity name];
label.font = [UIFont boldSystemFontOfSize:17];
label.backgroundColor = [UIColor clearColor];
[cell addSubview:label];
[label release];
//Mostramos la imagen
UIImageView *leftImage = [[UIImageView alloc] initWithFrame:CGRectMake(5, 3, 50, 50)];
[cell addSubview:leftImage];
UITextView *textView=[[UITextView alloc] initWithFrame:CGRectMake(60, 25, 200, 38)];
textView.editable = NO;
textView.backgroundColor = [UIColor clearColor];
textView.textColor = [UIColor grayColor];
textView.font = [UIFont systemFontOfSize:12.0];
textView.contentInset = UIEdgeInsetsMake(-8,-8,0,0);
textView.userInteractionEnabled=NO;
[cell addSubview:textView];
switch ([activity notType]) {
case 0:
textView.text = [NSString stringWithFormat:NSLocalizedString(#"requestPUSH",#""),[activity name]];
leftImage.image = [UIImage imageNamed:#"ios.png"];
break;
case 1:
textView.text = [NSString stringWithFormat:NSLocalizedString(#"MPCreatedPushString",#""),[activity name],[activity nameItem]];
leftImage.image = [UIImage imageNamed:#"mpNew.png"];
break;
case 2:
textView.text = [NSString stringWithFormat:NSLocalizedString(#"MPUpdatedPushString",#""),[activity name],[activity nameItem]];
leftImage.image = [UIImage imageNamed:#"mpUpdated.png"];
break;
case 3:
textView.text = [NSString stringWithFormat:NSLocalizedString(#"MPDeletedPushString",#""),[activity name],[activity nameItem]];
leftImage.image = [UIImage imageNamed:#"ios.png"];
break;
case 4:
textView.text = [NSString stringWithFormat:NSLocalizedString(#"MPGuestConfirmationPUSHString",#""),[activity name],[activity nameItem]];
leftImage.image = [UIImage imageNamed:#"attend.png"];
break;
case 5:
if ([[activity message] isEqualToString:#"noData"]) {
textView.text = [NSString stringWithFormat:NSLocalizedString(#"ShoutPushString",#""),[activity name]];
}else{
textView.text = [NSString stringWithFormat:NSLocalizedString(#"ShoutPushStringWithData",#""),[activity name], [activity message]];
}
UIImage *contactImage = [UIImage imageWithData:[[activity person] pic]];
if (contactImage!=nil) {
leftImage.image = contactImage;
//redondeamos bordes
CALayer * l = [leftImage layer];
[l setMasksToBounds:YES];
[l setCornerRadius:5.0];
}else{
leftImage.image = [UIImage imageNamed:#"ios.png"];
}
break;
case 6:
textView.text = [NSString stringWithFormat:NSLocalizedString(#"CheckinPushString",#""),[activity name],[activity nameItem]];
leftImage.image = [UIImage imageNamed:#"ios.png"];
break;
case 7:
textView.text = [NSString stringWithFormat:NSLocalizedString(#"MPGuestRejectionPUSHString",#""),[activity name],[activity nameItem]];
leftImage.image = [UIImage imageNamed:#"reject.png"];
break;
default:
break;
}
[leftImage release];
[textView release];
//Mostrar fecha
double timestamp = [[activity datetime] doubleValue]/1000;
NSString *dateShow;
NSDate *datetime = [NSDate dateWithTimeIntervalSince1970:timestamp];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:#"HH:mm"];
dateShow=[dateFormat stringFromDate:datetime];
UILabel *label2= [[UILabel alloc] initWithFrame:CGRectMake(240, 0, 70, 20)];
label2.text = dateShow;
label2.textAlignment = UITextAlignmentRight;
label2.font = [UIFont systemFontOfSize:12];
label2.backgroundColor = [UIColor clearColor];
label2.textColor = [UIColor blueColor];
[cell addSubview:label2];
[label2 release];
}
return cell;
}
Hmm, so you give each cell a unique cell identifier. Do you have a reason for that?
Mostly people try to patch their misunderstanding of iOS table views that way ...
When you reload your table this call UITableViewCell *cell = [ tableView dequeueReusableCellWithIdentifier: CellIdentifier];
will get you a cell to reuse (read already contains content).
But your code only works for "fresh" cells : if (cell == nil) {
, you're just not prepared for that case ...

Resources