I am trying to update the second last row of a tableview just after the last one (of the same kind) has been inserted. What I want is to change the image in a custom uiimageview i put in the xib.
I achieved this feature by calling [_tableView reloadData] just after the insertion, but this way the insert animation has gone and the performance have got worse.
Here is part of the code I wrote:
•in the delegate:
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
[_dataSource setIsRead:(BOOL)read AtIndexPath:indexPath];
[_dataSource configureCell:(WMChatTableViewCell *)cell AtIndexPath:indexPath];
[cell setNeedsUpdateConstraints];
[cell updateConstraintsIfNeeded];
[cell setNeedsLayout];
[cell layoutIfNeeded];
}
• in the dataSource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
WMMessage *message = [self messageAtIndexPath:indexPath];
/**
Message sent by the user
*/
if ([message.sender_id intValue] == [[[NSUserDefaults standardUserDefaults]valueForKey:kUserIdKey]intValue]) {
WMRightChatTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:rightTextIdentifier];
if (cell == nil) {
cell = [[WMRightChatTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:rightTextIdentifier];
}
[self configureCell:cell AtIndexPath:indexPath];
return cell;
}
/**
Message sent by the recipient
*/
else{
WMLeftChatTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:leftTextIdentifier];
if (cell == nil) {
cell = [[WMLeftChatTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:leftTextIdentifier];
}
[self configureCell:cell AtIndexPath:indexPath];
return cell;
}
return nil;
}
-(void)configureCell:(WMChatTableViewCell *)cell AtIndexPath:(NSIndexPath *)indexPath{
WMMessage *message = [self messageAtIndexPath:indexPath];
....
/**
Last message sent by the recipient
*/
if (!([message.sender_id intValue] == [[[NSUserDefaults standardUserDefaults]valueForKey:kUserIdKey]intValue]) &&
[message isEqual:[[_messagesMatrix lastObject]lastObject]]) {
/**
An highlighted version of the background.
Normally the left cell has the "BoxChat_sx" image, only when it's the last one, the image should change
*/
[cell.balloonImageView setImage:[UIImage imageNamed:#"BoxChat_sx_new"]];
....
}
else if(!([message.sender_id intValue] == [[[NSUserDefaults standardUserDefaults]valueForKey:kUserIdKey]intValue])){
/*
If it's not the last anymore, the image should change back to it's original state
*/
[cell.balloonImageView setImage:[UIImage imageNamed:#"BoxChat_sx"]];
...
}
}
Without calling [_tableView reloadData] this code won't update the imageView. Is there a way to achieve this feature without calling reloadData or, at least, keeping the insertion animation?
Related
I have a tableView where I select cells and add the data in an array, I also have the option of swiping and then deleting a particular cell which eventually deletes the data from the array.
The problem is that once I delete a row, I lose all my selection state after I reload the table,
For that I checked again with the selection array and reselected all these cells,
BUT I am stuck at one place, Much before I actually delete a cell and reload the tableView, as soon as I swipe over a cell, selection state of all other cells also go away.
NOTE: I have two arrays, one with list of itmes to be displayed in the tableView and one with the selected items.
Here is some code:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 50;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.contactList count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = #"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease];
}
cell.selectionStyle = UITableViewCellSelectionStyleGray;
[cell.textLabel setTextColor:[UIColor colorWithRed:103.0/255.0 green:103.0/255.0 blue:103.0/255.0 alpha:1.0]];
[cell.textLabel setFont:[UIFont fontWithName:#"ITCAvantGardeStd-Bk" size:14.0]];
if (![[[self.contactList objectAtIndex:indexPath.row] objectForKey:#"nickName"] isEqualToString:#""])
cell.textLabel.text = [NSString stringWithFormat:#"%#",[[self.contactList objectAtIndex:indexPath.row] objectForKey:#"nickName"]];
else
cell.textLabel.text = [NSString stringWithFormat:#"%# %#",[[self.contactList objectAtIndex:indexPath.row] objectForKey:#"firstName"],[[self.contactList objectAtIndex:indexPath.row] objectForKey:#"lastName"]];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(#"Selected cell index==>%d\n",indexPath.row);
//NSString *emailID = [NSString stringWithFormat:#"%#",[[self.contactList objectAtIndex:indexPath.row] objectForKey:#"email_key"]];
NSLog(#"emailID==>%#\n",[self.contactList objectAtIndex:indexPath.row]);
[self.emailShareList addObject:[self.contactList objectAtIndex:indexPath.row]];
//[self.emailShareList insertObject:emailID atIndex:indexPath.row];
NSLog(#"Array value==>%#\n",self.emailShareList);
//[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(#"deSelected cell index==>%d\n",indexPath.row);
NSString *emailID = [NSString stringWithFormat:#"%#",[[self.contactList objectAtIndex:indexPath.row] objectForKey:#"email_key"]];
NSLog(#"emailID==>%#\n",emailID);
[self.emailShareList removeObject:[self.contactList objectAtIndex:indexPath.row]];
NSLog(#"deSelect row Array value==>%#\n",self.emailShareList);
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
if(indexPath.row != 0)
{
NSString *contactID = [[self.contactList objectAtIndex:indexPath.row] objectForKey:#"contactId"];
NSLog(#"content on delete row==>%#\n",contactID);
[self.contactList removeObjectAtIndex:indexPath.row];
[self deleteContactToServer:contactID];
}
}
[contactTableView reloadData];
for (int i = 0; i < [self.emailShareList count]; i++)
{
for (int j = 0; j < [self.contactList count]; j++)
{
if([[[self.contactList objectAtIndex:j] valueForKey:#"email"] isEqualToString: [[self.emailShareList objectAtIndex:i] valueForKey:#"email"]])
{
NSIndexPath *path1 = [NSIndexPath indexPathForRow:j inSection:0];
[contactTableView selectRowAtIndexPath:path1 animated:NO scrollPosition:UITableViewScrollPositionNone];
}
}
}
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCellEditingStyle style = UITableViewCellEditingStyleNone;
if(indexPath.row != 0)
style = UITableViewCellEditingStyleDelete;
return style;
}
When you delete an item, you don't necessary have to reload the entire tableview. You could use the – deleteRowsAtIndexPaths:withRowAnimation: method to just remove the cell in question (along with an according model update). This will probably retain your selection.
To keep your selections when entering editing mode (swipe for delete is a special case of editing mode as well) you nee to do two things:
First, enable allowsSelectionDuringEditing on your tableView:
self.tableView.allowsSelectionDuringEditing = YES;
Second, create a UITableView subclass and override setEditing:animated: like this:
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
NSArray *indexPaths = self.indexPathsForSelectedRows;
[super setEditing:editing animated:animated];
for (NSIndexPath *ip in indexPaths) {
[self selectRowAtIndexPath:ip animated:NO scrollPosition:UITableViewScrollPositionNone];
}
}
Personally, I would rather use some sort of custom selection mechanism, when selections are important from a model point of view. I would create a custom cell subclass, add a selection property to it let it change the cell styling accordingly. The build-in features that affect regular table view selections won't cause problems with such an approach.
Here is an additional method of preserving table selections in and out of edit mode without having to subclass UITableView. Add the following to your UITableViewControllerView.
Within viewDidLoad add:
self.tableView.allowsSelectionDuringEditing = YES;
Then override setEditing:animated:
- (void)setEditing:(BOOL)editing animated:(BOOL)animate
{
NSArray *selectedIndexPaths = [self.tableView indexPathsForSelectedRows];
[super setEditing:editing animated:animate];
for (NSIndexPath *selectedIndexPath in selectedIndexPaths) {
[self.tableView selectRowAtIndexPath:selectedIndexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
}
}
I create a UITableView programmatically with different cells and sections that connects to the other views in storyboard like below picture:
My question is:
how can I connect these 3 cells to these different views ,would you please helping me
Thanks in advance!
Here is my code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *key = [[self sectionKeys] objectAtIndex:[indexPath section]];
NSArray *contents = [[self sectionContents] objectForKey:key];
NSString *contentForThisRow = [contents objectAtIndex:[indexPath row]];
static NSString *CellIdentifier = #"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
[[cell textLabel] setText:contentForThisRow];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
_selectedIndex = indexPath.row;
[self.tableView reloadData];
}
Edit:
When I use this method It just load the WorkTime view even if user select the absence cell,
Does any one knows why ?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
_selectedIndex = indexPath.row;
[self.tableView reloadData];
//maybe you could use a switch/case here, to assign the correct string to the segue identifier.
switch (indexPath.row){
case 0:
[self performSegueWithIdentifier:#"test" sender:self];
break;
case 1:
[self performSegueWithIdentifier:#"set" sender:self];
break;
case 2:
[self performSegueWithIdentifier:#"get" sender:self];
break;
}
}
Your last method is the way you want to go, but by the looks of it, you need to be checking indexPath.section not indexPath.row
In my code i want to select a cell in a UITableView. I perform the selection here, but every time it should be selected it gets selected only for a moment and then it loses its selection.
What did I do wrong?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"SimpleTableIdentifier"];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:#"SimpleTableIdentifier"];
}
cell.textLabel.text = [[self tableViewArray] objectAtIndex:indexPath.row];
if(indexPath.row == self.selectedTopicIndex)
{
NSLog(#"DIE DIE DIE DIE DIE!!!");
[cell setSelected:YES];
[cell setSelectionStyle:UITableViewCellSelectionStyleBlue];
[cell setSelected:YES];
}
return cell;
}
Just move your selection logic inside -tableView:willDisplayCell:forRowAtIndexPath: method.
Something like this:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.row == self.selectedTopicIndex)
{
NSLog(#"DIE DIE DIE DIE DIE!!!");
[cell setSelectionStyle:UITableViewCellSelectionStyleBlue];
[cell setSelected:YES];
}
}
I have created custom cells with a button that changes the state of a row from "availible" to "bought", and I also have an UIImageview which shows the state. I want the cell to redraw with the new state when the user presses the button.
I have been able to get the UIImage to be redrawn after the User scrolls the cell out of view. This is what I have so far:
Initialization
- (void)viewDidLoad
{
[super viewDidLoad];
self.clearsSelectionOnViewWillAppear = YES;
self.contentSizeForViewInPopover = CGSizeMake(600.0, 560.0);
//[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
[self.tableView setRowHeight:60];
[self.tableView setBackgroundColor:[UIColor blackColor]];
}
Got only one section:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
And all items are in the "paketListe" array:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [paketListe count];
}
The cellForRow function only gets called, when the cell is out of view and when the cell is initially drawn.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(#"CellForRow called!");
PaketTableViewCell *cell = [[[PaketTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil] autorelease];
[cell setDelegate:self];
Paket *tempPaket = [paketListe objectAtIndex:[indexPath row]];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *userDocumentsPath = [paths objectAtIndex:0];
NSString *fileName = [NSString stringWithFormat:#"%#/%#/%#",userDocumentsPath, [tempPaket productID], [tempPaket previewPic]];
[cell setProductIndex:[indexPath row]];
//... Setting some Attributes in my custom cell, cut out for simplicity....
cell.backgroundColor = [UIColor clearColor];
return cell;
}
The code for the Button, this is a delegate call, so my custom sell calls [delegate buttonPushed:(int)];
- (void) buttonPushed:(int) myProductIndex {
NSLog(#"Pushed: %#", [[paketListe objectAtIndex:myProductIndex] productID]);
CoreDataWrapper *tempCDW = [[CoreDataWrapper alloc] init];
[tempCDW initCoreData];
Paket *tempPaket = [paketListe objectAtIndex:myProductIndex];
//Doing some work in Core Data an my "paketListe" array. Left out for simplicity...
[tempCDW release];
//Here it begins....
[[self tableView] reloadData];
[[self tableView] beginUpdates];
[[self tableView] reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:myProductIndex inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
[[self tableView] endUpdates];
}
Now I tried the reloading with different commands... Reload the whole thing with just reloadData or the begin-/endUpdate thing. Nothing refreshes the cell. After several hours of reading I think I did everything right, but no refresh.
I appreciate any help.
Quick and dirty:
- (void)configureCell:(PaketTableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
//Any cell-specific code
[cell setNeedsLayout]; //or [cell setNeedsDisplay];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//Code to create any/a general cell
[self configureCell:cell];
return cell;
}
- (void) buttonPushed:(int) myProductIndex {
//Code to identify the cell in which your button is (use "super")
[self configureCell:cellForPushedButton];
}
I got to know your problem you have missed in reloadRowsAtIndexPaths "nil".
Do as i wrote below, it will work.
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:myProductIndex inSection:0], nil] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];
I'm having trouble adding cells with different content to my app. I know (or think) this needs to be done using an array, but I'm new to xcode and objective-c so I'm not exactly sure how to do this. Any help is much appreciated. Thanks.
Here is a copy of my current code:
#import "RootViewController.h"
#import "CustomCell.h"
#implementation RootViewController
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 5;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 100;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.imageViews.image = [UIImage imageNamed:#"captainaq_4.jpg"];
cell.firstLabel.text = #"name ";
cell.secondLabel.text = #"second name";
cell.thirdLabel.text = #"third name";
cell.thirdLabel.textAlignment = UITextAlignmentCenter;
// Configure the cell.
return cell;
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
// Delete the row from the data source.
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert)
{
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
}
}
*/
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:#"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
*/
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Relinquish ownership any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
// For example: self.myOutlet = nil;
}
- (void)dealloc
{
[super dealloc];
}
#end
First, note that cellForRowAtIndexPath is being called multiple times-- once for each cell. I think your best option would be to declare an array, and populate it with the objects you want displayed, as follows:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *days[] = {#"Mon", #"Tues", #"Wed", #"Thurs", #"Fri", #"Sat", #"Sun"};
static NSString *CellIdentifier = #"Cell";
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
[[cell textLabel] setText:days[indexPath.row]];
return cell;
}
Or populate the array somewhere else, if you need to manipulate the objects within it. In that case (assuming your array is populated with strings), your call to setText would look like:
[[cell textLabel] setText:[yourArray objectAtIndex:indexPath.row]];
It also appears you want to have a header with an image in it. In that case, use:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
//create your UIImageView and add your image
return yourImageView;
}
ok... as far as I have seen , I dont think the following is valid.
cell.imageViews.image = [UIImage imageNamed:#"captainaq_4.jpg"];
cell.firstLabel.text = #"name ";
cell.secondLabel.text = #"second name";
cell.thirdLabel.text = #"third name";
cell.thirdLabel.textAlignment = UITextAlignmentCenter;
Correct me if I am wrong...
As far as I understood your question, what you got to do is that create labels and add them either programmatically or through Interface Builder ( whichever is easier for you) so that you can display whatever contents you want in the cell...
Here is an example of what you can do..
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; // adding indicator to the rows
}
// Configure the cell...
switch (indexPath.row) {
case 0:
cell.textLabel.text = #"John Doe";
cell.detailTextLabel.text = #"DEPT";
//cell.imageView.image = [UIImage imageNamed:#"meeting_color.png"];
break;
case 1:
cell.textLabel.text = #"Mary Smith";
cell.detailTextLabel.text = #"DEPT";
//cell.myImageView.image = [UIImage imageNamed:#"call_color.png"];
break;
case 2:
cell.textLabel.text = #"Bob Wong";
cell.detailTextLabel.text = #"DEPT";
//cell.myImageView.image = [UIImage imageNamed:#"calendar_color.png"];
break;
default:
break;
}
return cell;
}
Again that is a very simple way you can add content to a tableview...
You can create several different UITableViewCell or your own custom cell class and add it into array and display it later under:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
}
With this, you can have several distinct custom cell (What I mean distinct is totally different cell, such as first cell with image while the other doesn't have image).
While the other alternative is to do it inside the
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
as shown by using switch case. Either ways, it's about preference.
I suggest you to learn more about the basic use of classes, such as NSArray, NSMutableArray, and writing Objective-C language first. While it doesn't help much with learning developing app, it will speed up the learning curve during the real implementation of building program in Cocoa environment.