Update UItableView in viewWillAppear? - ios

I have problem with my UItableview that when I use viewWillAppear for retrieving updated data each time table is viewed this gives me exception .
Please can any one help me on how to refresh tableview in viewWillAppear so that it will be updated before CellforrowAtindexPath is called ?
Here is my code for viewWillAppear:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
[self.tableView reloadData];//table was filled in viewDidLoad.
}
Here is CellforrowAtindexPath` : (The exception is on mainArray which means that there is conflict in updating table through viewWillAppear and calling cell ):
//Methods to retrive all selected words , thier sound and picture for the mother
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifer = #"Cell";
UITableViewCell *cell= [ tableView dequeueReusableCellWithIdentifier:CellIdentifer];
cell.textLabel.font = [UIFont systemFontOfSize:17.0];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifer];
}
cell.textLabel.font = [UIFont systemFontOfSize:17.0];
UILabel *label ;
label=(UILabel *)[cell viewWithTag:1];
NSString *value = [[self.mainArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
label.text = value;
label.textAlignment=NSTextAlignmentRight;
label.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
//self.tableView.separatorColor = [UIColor blackColor];TRY TO SEPARETE BETEWEEN LINES OF TABLE
UIButton *butt =(UIButton *)[cell viewWithTag:2];
NSString *value2 = [[self.mainArray2 objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
butt.restorationIdentifier= value2;
[butt addTarget:self action:#selector(play:) forControlEvents:UIControlEventTouchUpInside];
NSString *value3 = [[self.mainArray3 objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageNamed:value3];
label.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
return cell;
}

(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;{
return self.mainArray.count;
}
if count is 0, table view won't call the other functions.

Related

How to set the text and detail text of cell in tableview?

I am getting this type of data inside cell. How to set the text and detail text of cell so that both text may appear in readable format.
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #"SimpleTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.font=[UIFont fontWithName: #"Arial" size: 14.0 ];
cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
[cell setBackgroundColor:[UIColor whiteColor]];
UILabel *idLabel = (UILabel*)[cell.contentView viewWithTag:201];
if(!idLabel)
{
idLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 200, 50)];
cell.textLabel.textColor = [UIColor blackColor];
idLabel.tag = 201;
[cell.contentView addSubview:idLabel];
}
idLabel.text = [arrayFiltered objectAtIndex:indexPath.row];
cell.textLabel.text = [idArray objectAtIndex:indexPath.row];
cell.textLabel.textColor = [UIColor grayColor];
cell.detailTextLabel.text = [descArray objectAtIndex:indexPath.row];
cell.detailTextLabel.textColor = [UIColor blueColor];
cell.detailTextLabel.numberOfLines = 2;
cell.detailTextLabel.adjustsFontSizeToFitWidth = YES;
return cell;
}
The code which i have written is above.
Please help me.
We have 3 or more options to achieve this.I explain you step by step process
I create the tableView and hook up.
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>
#property (strong, nonatomic) IBOutlet UITableView *tblView;
#end
ViewController.m
#import "ViewController.h"
#import "CustomCell.h" // For CustomCell using,we have to import.
#interface ViewController ()
{
NSMutableArray *idArray;
NSMutableArray *descArray;
}
#end
#implementation ViewController
In viewDidLoad method I added the objects to id desc array.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
idArray = [[NSMutableArray alloc]initWithObjects:#"INOX",#"Sathyam",#"PVR",#"IMAX",nil];
descArray = [[NSMutableArray alloc]initWithObjects:#"INOX currently operates 107 multiplexes and 420 screens in 57 cities across India",#"SPI Cinemas is an Indian multiplex chain and film production company owned by the SPI Group, headquartered in Chennai.",#"The IMAX cinema process increases the image resolution by using larger film frame;",#"PVR Cinemas is the largest and the most premium film entertainment company in India.",nil];
}
Below tableView datasource methods
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return idArray.count;
}
Now I have 3 options for achieving your requirement.But all these are implemented in cellForRowAtIndexPath method.
FIRST OPTION:UITableViewCellStyleDefault-If you use this, you can implement the code in cellForRowAtIndexPath like below
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *strCell = #"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:strCell];
if(cell==nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:strCell];
}
UILabel *idLabel = [[UILabel alloc]init];
idLabel.frame = CGRectMake(15, 13, 168, 24);
idLabel.tag = indexPath.row;
idLabel.numberOfLines = 1;
idLabel.font = [UIFont fontWithName:#"HelveticaNeue" size:18];
idLabel.textAlignment = NSTextAlignmentLeft;
idLabel.textColor = [UIColor blackColor];
idLabel.text = [NSString stringWithFormat:#"%#",[idArray objectAtIndex:indexPath.row]];
[cell.contentView addSubview:idLabel];
UILabel *descLabel = [[UILabel alloc]init];
descLabel.frame = CGRectMake(15, 47, 348, 34);
descLabel.tag = indexPath.row;
descLabel.numberOfLines = 2;
descLabel.font = [UIFont fontWithName:#"HelveticaNeue" size:12];
descLabel.textAlignment = NSTextAlignmentLeft;
descLabel.textColor = [UIColor blueColor];
descLabel.text = [NSString stringWithFormat:#"%#",[descArray objectAtIndex:indexPath.row]];
[cell.contentView addSubview:descLabel];
return cell;
}
SECOND OPTION:UITableViewCellStyleSubtitle - If you use this, you can implement the code in cellForRowAtIndexPath like below
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *strCell = #"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:strCell];
if(cell==nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:strCell];
}
cell.textLabel.text = [NSString stringWithFormat:#"%#",[idArray objectAtIndex:indexPath.row]];
cell.textLabel.tag = indexPath.row;
cell.textLabel.numberOfLines = 1;
cell.textLabel.font = [UIFont fontWithName:#"HelveticaNeue" size:18];
cell.textLabel.textAlignment = NSTextAlignmentLeft;
cell.textLabel.textColor = [UIColor blackColor];
cell.detailTextLabel.text = [NSString stringWithFormat:#"%#",[descArray objectAtIndex:indexPath.row]];
cell.detailTextLabel.tag = indexPath.row;
cell.detailTextLabel.numberOfLines = 2;
cell.detailTextLabel.font = [UIFont fontWithName:#"HelveticaNeue" size:12];
cell.detailTextLabel.textAlignment = NSTextAlignmentLeft;
cell.detailTextLabel.textColor = [UIColor blueColor];
return cell;
}
THIRD OPTION : CUSTOM CELL - If you use Custom Cell you have to import the CustomCell.h first.After that you have to do the following things in cellForRowAtIndexPath method
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:#"cell"];
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"CustomCell" owner:self options:nil];
if(cell == nil){
cell = nib[0];
}
cell.idLabel.text = [NSString stringWithFormat:#"%#",[idArray objectAtIndex:indexPath.row]];
cell.idLabel.tag = indexPath.row;
cell.idLabel.numberOfLines = 1;
cell.idLabel.font = [UIFont fontWithName:#"HelveticaNeue" size:18];
cell.idLabel.textAlignment = NSTextAlignmentLeft;
cell.idLabel.textColor = [UIColor blackColor];
cell.descLabel.text = [NSString stringWithFormat:#"%#",[descArray objectAtIndex:indexPath.row]];
cell.descLabel.tag = indexPath.row;
cell.descLabel.numberOfLines = 2;
cell.descLabel.font = [UIFont fontWithName:#"HelveticaNeue" size:12];
cell.descLabel.textAlignment = NSTextAlignmentLeft;
cell.descLabel.textColor = [UIColor blueColor];
return cell;
}
I attached the screen shot of custom cell.It shows you what I have done there.
SNAPCHAT 1:idLabel
SNAPCHAT 2:descLabel
You can use heightForRowAtIndexPath method for setting row height.It is UITableViewDelegate method
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 90;
}
NOTE:Generally I set the tag for label is idLabel.tag = indexPath.row.According
to your requirement set the tag here.
I created and worked out the sample application for you.All I have done successfully.
Use cell textLable and detailTextLable to show your data like below code-
cell.textLabel.text=#"your text";
cell.detailTextLabel.text=#"your text";
idLabel overrides the position of the textlabel .
If
you want to put the id before the text , You can combine both the string and put into the textlabel.
else
use dont use textlabel and detail textlabel, create all the three labels of your own and align properly using Frame values.
Check the Height of the Cell and calculate it according to the Cell Text and number of lines of Label. And move your Font, Background Color, Line Break settings of label inside cell == nil.
Edit: to adjust three Labels you would need custom Cell or if you can concatenate it with Text Label. It all depends on your requirement.

Expandable UITableViewCell overlapping other cells

I'm working on a UITableView with expandable cells and I got it working with:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if(_selectedCellIndexPath != nil
&& [_selectedCellIndexPath compare:indexPath] == NSOrderedSame)
return 160;
return 40;
}
and
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
_selectedCellIndexPath = indexPath;
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
}
And the UITableViewCell set up in Storyboard as:
But when I change it to this:
to add the description and button, it scrambles up everything like this:
How come the description textview and more info button are showing even though the heightForRowAtIndexPath is 40 and they should be 'hidden'?
Or am I taking a wrong approach to this?
Also, the tapping and expanding is not applied to the searchDisplayController.searchResultsTableView. How can I do this?
Edit: cellForRowAtIndexPath method:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = #"IngredientCell";
UITableViewCell *cell= [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.backgroundColor = [UIColor colorWithRed:1.000 green:1 blue:1 alpha:0.333];
cell.tintColor = [UIColor whiteColor];
UILabel *title = (UILabel*) [cell viewWithTag:1];
UILabel *summary = (UILabel*) [cell viewWithTag:2];
UIButton *moreInfo = (UIButton*) [cell viewWithTag:3];
summary.hidden = YES;
moreInfo.hidden = YES;
[title setTextColor: [UIColor whiteColor]];
// Display recipe in the table cell
if (tableView == self.searchDisplayController.searchResultsTableView) {
[title setText: [searchResults objectAtIndex:indexPath.row]];
//set summary
} else {
[title setText: [ingredients objectAtIndex:indexPath.row]];
//set summary
}
// Change color if dissallowed
if ([[title text] rangeOfString:#"Egg"].location != NSNotFound) {
cell.backgroundColor = [UIColor colorWithRed:1.000 green:0.350 blue:0.485 alpha:0.333];
}
// Change color when selected
UIView *customColorView = [[UIView alloc] init];
customColorView.backgroundColor = [UIColor clearColor];
cell.selectedBackgroundView = customColorView;
return cell;
}

Adding UILabel in custom cell issue

I have custom cell in my UITableView and according to the string's value I want to add a UILabel in the cell.
Here is my code for cell,
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary * tmpDictn = [tableAry objectAtIndex:indexPath.section];
NSString * typeStr = [tmpDictn objectForKey:#“DocumentType”];
NSString * cellIdentifier = #"TestCell";
TestCell *cell = (TestCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell){
cell = [[TestCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
if ([typeStr isEqualToString:#“Text”]) {
UILabel * textLbl = [[UILabel alloc] init];
textLbl.backgroundColor=[UIColor clearColor];
textLbl.textColor=[UIColor lightGrayColor];
textLbl.userInteractionEnabled=NO;
textLbl.numberOfLines = 0;
textLbl.font = [UIFont fontWithName:#“Helvetica" size:16];
[textLbl setFrame:CGRectMake(30, 20, 250, 25)];
textLbl.text= [NSString stringWithFormat:#"%# %i",[splitAry objectAtIndex:i],indexPath.section];
[cell addSubview:textLbl];
}
}
return cell;
}
My UITableView contain 5 cell(dynamic). And only first cell should have this label(this also change according to Text). This code is adding UILabel in first cell but also add UILabel at 3 and 5th cell.
I have checked that its same UILabel created 1 time and added in cell 1st, 3rd and 5th. And "Text" is only at first position in Tableary.
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary * tmpDictn = [tableAry objectAtIndex:indexPath.section];
NSString * typeStr = [tmpDictn objectForKey:#“DocumentType”];
NSString * cellIdentifier = #"TestCell";
TestCell *cell = (TestCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell){
cell = [[TestCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
UILabel *lbl = [cell viewWithTag:1];
if(lbl)
{
[lbl removeFromSuperView];
}
if ([typeStr isEqualToString:#“Text”]) {
UILabel * textLbl = [[UILabel alloc] init];
textLabel.tag = 1;
textLbl.backgroundColor=[UIColor clearColor];
textLbl.textColor=[UIColor lightGrayColor];
textLbl.userInteractionEnabled=NO;
textLbl.numberOfLines = 0;
textLbl.font = [UIFont fontWithName:#“Helvetica" size:16];
[textLbl setFrame:CGRectMake(30, 20, 250, 25)];
textLbl.text= [NSString stringWithFormat:#"%# %i",[splitAry objectAtIndex:i],indexPath.section];
[cell addSubview:textLbl];
}
}
return cell;
}
Try using a different cell identifier for the cells that need a label added to them, e.g. #"TextCell". Otherwise, you are reusing cells that already have a label added even if it is not supposed to be there. Alternatively, you could remove the label (if it is there) in an 'else' condition of your if ([typeStr isEqualToString:#“Text”]) block but I think that the former is cleaner.
You are using
[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
The problem for your code is that table view is reusing your cell. So it will appear in many as your number of cells increases.
I am a bit old programmer but I think the best way is to
if (!cell)
{
cell = [[TestCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
//Add your label here.
}
if(!label)
{ //your code;
//set label text to nil if your condition not met;
}
A quick solution for you is to put an else and set text to nil;
Cheers.

Having issue using dequeueReusableCellWithIdentifier within cellForRowAtIndexPath

I'm using below code to add a text label into a static table with 4 sections and 3 row in each.
for some reason, when I first run the app its fine, but when I scroll up and down, the UItable doesn't show up properly. Can someone tell why?
NSString *identifer = #"net";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifer] ;
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer];
UILabel *Net= [[UILabel alloc] initWithFrame:CGRectMake(15, 15, 220.0, 15.0)];
Net.tag = indexPath.row;
Net.text = [NSString stringWithFormat:#"%ld",(long)indexPath.row];
Net.textColor= [UIColor blackColor];
Net.font=[UIFont systemFontOfSize:14.0];
[cell addSubview:Net];
}else {
UILabel *Label1 =(UILabel*) [cell viewWithTag:indexPath.row];
Label1.text =[NSString stringWithFormat:#"%d",indexPath.row];
Label1.font=[UIFont systemFontOfSize:14.0];
}
return cell;
I don't think you need and else statement while building your cell, this is an edited code that may work out for you:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 4;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *identifer = #"net";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifer] ;
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer];
UILabel *Net= [[UILabel alloc] initWithFrame:CGRectMake(15, 15, 220.0, 15.0)];
// Net.tag = indexPath.row;
Net.text = [NSString stringWithFormat:#"%d",indexPath.row];
Net.textColor= [UIColor blackColor];
Net.font=[UIFont systemFontOfSize:14.0];
[cell addSubview:Net];
}
/*else {
UILabel *Label1 =(UILabel*) [cell viewWithTag:indexPath.row];
Label1.text =[NSString stringWithFormat:#"cell nr. %d",indexPath.row];
Label1.font=[UIFont systemFontOfSize:14.0];
}
*/
return cell;
}
I've commented your last lines of code so you won't lose them. If you also set the style of your TabelView as "Grouped", the result you'll get is the following:
http://s2.postimg.org/820thcmy1/i_OS_Simulator_Screen_shot_26_giu_2014_14_46_41.png
Hope this helps!

How to set two array data in one cell content of custom tableview in ios?

hello I am beginner in iOS I have created custom table view and I have Two array then I want to set both array data together in simultaneously one by one cell content in table view I show image which i want..
Please refer : http://i.stack.imgur.com/WIkaf.png
NSMutableArray *SearchPatientCode;
NSMutableArray *SearchPatientName;
UITableView *table_SearchPatient;
SearchPatientCode=[[NSMutableArray alloc]initWithObjects:#"PH230130420",#"PH230420321",#"Ph450362120", nil];
SearchPatientName=[[NSMutableArray alloc]initWithObjects:#"Rahul Sharma",#"Amit kumar",#"anil sharma", nil];
table_SearchPatient=[[UITableView alloc]initWithFrame:CGRectMake(130,40,170,250)style:UITableViewStylePlain];
table_SearchPatient.delegate=self;
table_SearchPatient.dataSource=self;
table_SearchPatient.layer.borderWidth = 2.0;
table_SearchPatient.layer.borderColor = [UIColor grayColor].CGColor;
[self.view addSubview:table_SearchPatient];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *MyIdentifier = #"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if(tableView==table_SearchPatient)
{
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] ;
}
cell.textLabel.text =[NSString stringWithFormat:#"%# /n %#",[SearchPatientCode objectAtIndex:indexPath.row],[SearchPatientName objectAtIndex:indexPath.row]];
cell.textLabel.font = [UIFont fontWithName:#"Helvetica-Bold" size:10.0f];
// cell.detailTextLabel.text=[SearchPatientName objectAtIndex:indexPath.row];
}
return cell;
}
I am using this But this is not show as I want ...Solve this problem!!
Add New UILable with numberOfLines = 2 like bellow...
if you want to unlimited line with your content data then you can do it with set numberOfLines = 0 and set lineBreakMode = UILineBreakModeWordWrap
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *MyIdentifier = #"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if(tableView==table_SearchPatient)
{
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] ;
}
UILabel *lbl = [[UILabel alloc]init];
lbl.text = [NSString stringWithFormat:#"%# /n %#",[SearchPatientCode objectAtIndex:indexPath.row],[SearchPatientName objectAtIndex:indexPath.row]];
lbl.font = [UIFont fontWithName:#"Helvetica-Bold" size:10.0f];
[lbl setFrame:CGRectMake(20, 2, 250, 35)];// set frame which you want
[lbl setBackgroundColor:[UIColor clearColor]];// set any color here
// lbl.lineBreakMode = UILineBreakModeWordWrap; // set it if you want to height of UILable with its content (Multiple line)
lbl.numberOfLines = 2;// Add this line // Set 0 if you want to multiple line.
[cell.contentView addSubview:lbl];
}
return cell;
}
You can use detail cell.detailTextLabel.text.
Or You can create a custom cell and add the labels to the cell like this
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] ;
}
cell.textLabel.text = #"";
label_name_one = [[[UILabel alloc]initWithFrame:CGRectMake(10, 10, 90, 20)]autorelease];
[label_name_one setText:[SearchPatientCode objectAtIndex:indexPath.row]];
label_name_two = [[[UILabel alloc]initWithFrame:CGRectMake(92, 30, 170, 80)]autorelease];
[label_name_two setText:[SearchPatientCode objectAtIndex:indexPath.row]];
set the RectFrame according to your requirements.
Firstly change your cell style as UITableViewCellStyleValue2 then Use this code for multiline text in cell :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * cellIdentifier = #"MyIdentifier";
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2
reuseIdentifier:cellIdentifier];
[[cell textLabel] setFont:[UIFont fontWithName:#"Helvetica-Bold" size:10.0f]];
}
[[cell detailTextLabel] setText:[NSString stringWithFormat:#"%# %#",[SearchPatientCode objectAtIndex:indexPath.row],[SearchPatientName objectAtIndex:indexPath.row]]];
cell.detailTextLabel.numberOfLines = 2;
cell.detailTextLabel.lineBreakMode = NSLineBreakByWordWrapping;
return cell;
}
Hope it helps you.
Also make sure you check out the free Sensible TableView framework. Given the arrays, the framework will automatically display all the values in the table view, and will even generate detail views where applicable. Saves me tons of time.

Resources