UITableview , dynamically section & rows - ios

want create a uitableview dynamically with 2 rows in one section
i write this code but i have problem the repeats only 2 first rows in all sections
now i have this row 0,1 -> section 0 , row 0,1 -> section 1 , row 0,1 -> section 2
want read all rows after for example row 0,1 -> section 0 , row 2,3 -> section 1 , row 4,5 -> section 2 -> row 6,7
items = [[NSMutableArray alloc] init];
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{ return items.count/2; }
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{ return 2; }
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
UILabel *label = nil;
cell = [tv dequeueReusableCellWithIdentifier:#"Cell"];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:#"Cell"] autorelease];
label = [[UILabel alloc] initWithFrame:CGRectZero];
[label setLineBreakMode:UILineBreakModeWordWrap];
[label setMinimumFontSize:FONT_SIZE];
[label setNumberOfLines:0];
[label setFont:[UIFont systemFontOfSize:FONT_SIZE]];
[label setTag:1];
label.textColor = [UIColor darkGrayColor];
[label setAlpha:0.8];
cell.backgroundColor = [UIColor whiteColor];
[[cell contentView] addSubview:label];
}
NSString *text = [items objectAtIndex:[indexPath row]];
CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);
CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
if (!label)
label = (UILabel*)[cell viewWithTag:1];
[label setText:text];
[label setFrame:CGRectMake(CELL_CONTENT_MARGIN-5, CELL_CONTENT_MARGIN+30, CELL_CONTENT_WIDTH - ((CELL_CONTENT_MARGIN * 2)+6), MAX(size.height, 44.0f))];
label.backgroundColor = [UIColor clearColor];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
for (UIView *theSubview in [cell.contentView subviews])
{
if([theSubview isKindOfClass:[UIImageView class]])
{
[theSubview removeFromSuperview];
}
}
UIImageView *imv = [[UIImageView alloc]initWithFrame:CGRectMake(128,5, 32, 32)];
imv.image=[UIImage imageNamed:#"0England.png"];
[cell.contentView addSubview:imv];
[imv release];
if (indexPath.row % 2==0) {
UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(-7 ,10, 8, 18)];
img.image=[UIImage imageNamed:#"...."];
[cell.contentView addSubview:img];
[img release];
}
else { }
return cell;
}

You have a problem in your mapping of indexPaths to the rows of your data structure (in this case, your items array). Each section will be numbered from 0 to ceil(n/2) (which, by the way, should be the number of sections, not simply n/2) where n is the number of elements in items.
Each row inside the section will have an indexPath.row of 0 or 1.
Therefore, in order to map from indexPaths back to your items array, you have to do something like this in your cellForRowAtIndexPath function:
NSString *text = [items objectAtIndex:([indexPath section]*2 + [indexPath row])];

Related

How to show different labels in different sections?

I want to set labels in section... How can i set different labels in different section cz in tableview i want to make different sections and i am using the title for header in section.. by doing this i make different sections correctly but not able to differentiate the data between the sections.. Anyone can help me
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
// create the parent view that will hold header Label
UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(0,-60,300,60)];
// create the label object
UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
headerLabel.frame = CGRectMake(0,0,self.view.frame.size.width,60);
UIColor* mainColor = [UIColor colorWithRed:47.0/255 green:168.0/255 blue:228.0/255 alpha:1.0f];
headerLabel.backgroundColor = mainColor;
headerLabel.font = [UIFont boldSystemFontOfSize:18];
headerLabel.textAlignment = UITextAlignmentCenter;
//
// UILabel *firstSection = [[UILabel alloc] initWithFrame:CGRectZero];
// firstSection.frame = CGRectMake(0,0,self.view.frame.size.width,60);
//
// firstSection.font = [UIFont boldSystemFontOfSize:18];
UIView *firstSection = [[UIView alloc] initWithFrame:CGRectMake(0,-60,300,60)];
//headerLabel.textAlignment = UITextAlignmentCenter;
if(section == 0)
headerLabel.text = #"Reciever Party";
UILabel *nameLbl =[[UILabel alloc]initWithFrame:CGRectMake(20, 35, 100 ,50)];
nameLbl.text =#"Name";
nameLbl.textColor=[UIColor blackColor];
UIFont *bold = [UIFont boldSystemFontOfSize:[UIFont systemFontSize]];
[nameLbl setFont:bold];
nameLbl.backgroundColor =[UIColor clearColor];
[headerLabel addSubview:nameLbl];
UILabel *addLbl =[[UILabel alloc]initWithFrame:CGRectMake(20, 65, 100 ,50)];
addLbl.text =#"Address";
addLbl.textColor=[UIColor blackColor];
UIFont *bold1 = [UIFont boldSystemFontOfSize:[UIFont systemFontSize]];
[addLbl setFont:bold1];
addLbl.backgroundColor =[UIColor clearColor];
[headerLabel addSubview:addLbl];
if(section == 1)
headerLabel.text = #"Sender Party";
UILabel *senderName =[[UILabel alloc]initWithFrame:CGRectMake(20, 125, 100 ,50)];
senderName.text =#"Address";
senderName.textColor=[UIColor blackColor];
UIFont *bold2 = [UIFont boldSystemFontOfSize:[UIFont systemFontSize]];
[addLbl setFont:bold2];
senderName.backgroundColor =[UIColor clearColor];
[headerLabel addSubview:senderName];
if(section == 2)
headerLabel.text = #"Third Section Header";
headerLabel.textColor = [UIColor whiteColor];
[customView addSubview:headerLabel];
return customView;
}
I am giving you a sample with hard coded data that how can you show data in section tableView. viewForHeaderInSection is responsible for creating headers of each section, not for showing data in section's row.
I am adding label on cell's content view as you don't want to add this from storyboard/ prototype cell.
Try this:-
In cellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"YourIdentifier"];
/*
* If the cell is nil it means no cell was available for reuse and that we should
* create a new one.
*/
if (cell == nil) {
/*
* Actually create a new cell (with an identifier so that it can be dequeued).
*/
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:#"YourIdentifier"];
UILabel *lbl =[[UILabel alloc]initWithFrame:CGRectMake(20, 15, 100 ,50)];
lbl.textColor=[UIColor blackColor];
UIFont *bold1 = [UIFont boldSystemFontOfSize:[UIFont systemFontSize]];
[lbl setFont:bold1];
lbl.hidden = NO;
lbl.tag = 101;
lbl.backgroundColor =[UIColor clearColor];
[cell.contentView addSubview:lbl];
}
UILabel *lblCell = (UILabel*)[cell.contentView viewWithTag:101];
if(indexPath.section == 0) //first section
{
if (indexPath.row == 0) //first row of first section
{
lblCell.text =#"Name";
}
if (indexPath.row == 1) //second row of first section
{
lblCell.text =#"Address";
}
}
if(indexPath.section == 1) //second section
{
if (indexPath.row == 0) //first row of second section
{
lblCell.text =#"age";
}
if (indexPath.row == 1) //second row of second section
{
lblCell.text =#"phone no.";
}
}
if(indexPath.section == 2) //third section
{
if (indexPath.row == 0) //first row of third section
{
lblCell.text =#"city";
}
if (indexPath.row == 1) //second row of third section
{
lblCell.text =#"father";
}
}
/* Now that the cell is configured we return it to the table view so that it can display it */
return cell;
}
you have to use like that
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 40;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *sectionView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 225, 40)];
UIImageView *sectionImage = [[UIImageView alloc]initWithFrame:CGRectMake(5, 0, 40, 40)];
sectionImage.image = [UIImage imageNamed:[objMenuImageList objectAtIndex:section]];
sectionImage.contentMode = UIViewContentModeCenter;
[sectionView addSubview:sectionImage];
UILabel *sectionLable = [[UILabel alloc]initWithFrame:CGRectMake(50, 10, 150, 20)];
sectionLable.contentMode = UIViewContentModeLeft;
sectionLable.text = [objMenuList objectAtIndex:section];
[sectionLable setFont:[UIFont systemFontOfSize:14]];
sectionLable.textColor = [UIColor colorWithRed:(206/255.f) green:(180/255.f) blue:(116/255.f) alpha:1.0f];
[sectionView addSubview:sectionLable];
UIButton *sectionButton = [UIButton buttonWithType:UIButtonTypeCustom];
sectionButton.frame = CGRectMake(0, 0, sectionView.frame.size.width, sectionView.frame.size.height -10);
sectionButton.center = sectionView.center;
sectionButton.tag = section;
// sectionButton.backgroundColor = [UIColor yellowColor];
[sectionButton addTarget:self action:#selector(ExpandCell:) forControlEvents:UIControlEventTouchUpInside];
[sectionView addSubview:sectionButton];
sectionView.backgroundColor = [UIColor clearColor];
return sectionView;
}
Just keep It simple And Flexible.
Do it like this..
Step 1. Add one custom cell For Header View with UILabel for title.
Step 2. In cellForRowAtIndexPath , dequeueReusableCellWithIdentifier this cell .
Use condition as...
` if(section==0){
Cell.title.text= #"your title for section 0"
} // here title is UILabel `
By doing this your code is Flexible enough for Any Future Changes!!!

Resize UIImageView in UITableViewCell , with textlabel dynamically

i want to one size UIimageview for all cell , but
when the high size of cell is change the image is changed i want to one size of UIimage
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:#"Cell"];
if(!cell){
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"Cell"];
}
cell.imageView.image = [UIImage imageNamed:#"England.png"];
cell.imageView.frame = CGRectMake( 2, 0, 25, 25 );
cell.imageView.contentMode = UIViewContentModeScaleAspectFill;
UIFont * myfont = [UIFont fontWithName:#"Helvetica" size:13.0];
cell.textLabel.text = [_data objectAtIndex:indexPath.row];
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.numberOfLines = 0;
cell.textLabel.textAlignment = UITextAlignmentCenter;
cell.textLabel.font = myfont;
cell.textLabel.textColor = [UIColor grayColor];
return cell;
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString * description = [_data objectAtIndex:indexPath.row];
CGSize size = [description sizeWithFont:[UIFont boldSystemFontOfSize:14.0f] constrainedToSize:CGSizeMake(190,40) lineBreakMode:UILineBreakModeWordWrap];
return size.height+50;
}
Here are the codes
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
NSString *text = [items objectAtIndex:[indexPath row]];
CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);
CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
CGFloat height = MAX(size.height, 44.0f);
return height + (CELL_CONTENT_MARGIN * 5);
}
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
UILabel *label = nil;
cell = [tv dequeueReusableCellWithIdentifier:#"Cell"];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:#"Cell"] autorelease];
label = [[UILabel alloc] initWithFrame:CGRectZero];
[label setLineBreakMode:UILineBreakModeWordWrap];
[label setMinimumFontSize:FONT_SIZE];
[label setNumberOfLines:0];
[label setFont:[UIFont systemFontOfSize:FONT_SIZE]];
[label setTag:1];
[[cell contentView] addSubview:label];
}
NSString *text = [items objectAtIndex:[indexPath row]];
CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);
CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
if (!label)
label = (UILabel*)[cell viewWithTag:1];
[label setText:text];
[label setFrame:CGRectMake(CELL_CONTENT_MARGIN-10, CELL_CONTENT_MARGIN+30, CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), MAX(size.height, 44.0f))];
UIImageView *imv = [[UIImageView alloc]initWithFrame:CGRectMake(128,5, 32, 32)];
imv.image=[UIImage imageNamed:#"England.png"];
[cell.contentView addSubview:imv];
[imv release];
return cell;
}

Unable to get image/cell tag number in didrowselect method...!

Hi am using 2 UIImageView in a cellrow with tag, each row is displayed sequentially by populating images from an array like (0th image,1st image) for row 0, and (2nd image,3rd image) for row 1 and so on...
i am successful in displaying the image with appropriate tag for each image, but am unsuccessful in getting the tag for image or cell in didrowselect method...i need the tag number to directly pass the tagnumber as array index to detailsegue...Am new to IOS programming, i would like to know if am doing anything wrong here, please suggest a way to get the appropriate tag number...your help in this regard is greatly appreciated, as am struck with only this task to be completed!!!
Pasted my code for your reference: self.tagnumber=0; this code is for displaying even number of images.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//Check Even Rows or odd rows
if(_objects.count%2==0)
{
return (_objects.count/2);
}
else
{
return ((_objects.count/2)+1);
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyCellIdentifier = #"MyCellIdentifier";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:MyCellIdentifier];
if(cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyCellIdentifier];
}
NSInteger itemcount = _objects.count;
NSLog(#"RowCount:%d",_objects.count/2);
if(itemcount%2==0)
{
NSLog(#"Image Count is Even!");
if(itemcount!=self.tagnumber)
{
RSSItem *object = _objects[self.tagnumber];
UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(10, 4, 145, 95)];
imageView1.tag = self.tagnumber;//1;
NSLog(#"Tag number for Image1:%d", self.tagnumber);
imageView1.image = [UIImage imageWithData:object.artimageData];
[imageView1 setContentMode:UIViewContentModeScaleAspectFill];
[imageView1 setClipsToBounds:YES];
[cell.contentView addSubview:imageView1];
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(10, 100, 145, 30)];
label1.tag = self.tagnumber;
[label1 setFont:[UIFont fontWithName:#"AppleGothic" size:14.0]];
[label1 setTextColor:[UIColor blackColor]];
[label1 setContentMode:UIViewContentModeScaleToFill];
[label1 setTextAlignment:NSTextAlignmentCenter];
label1.text = #"Added 2days ago";;
[label1 setNumberOfLines:1];
[cell.contentView addSubview:label1];
//Display next Image
self.tagnumber++;
object = _objects[self.tagnumber];
UIImageView *imageView2= [[UIImageView alloc]initWithFrame:CGRectMake(165, 4, 145, 95)];
imageView2.tag =self.tagnumber;
NSLog(#"Tag number for Image2:%d", self.tagnumber);
imageView2.image = [UIImage imageWithData:object.artimageData];
[imageView2 setContentMode:UIViewContentModeScaleAspectFill];
[imageView2 setClipsToBounds:YES];
[cell.contentView addSubview:imageView2];
UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(165, 100, 145, 30)];
label2.tag = self.tagnumber;
[label2 setFont:[UIFont fontWithName:#"AppleGothic" size:14.0]];
[label2 setTextColor:[UIColor blackColor]];
[label1 setContentMode:UIViewContentModeScaleToFill];
[label2 setTextAlignment:NSTextAlignmentCenter];
label2.text = #"Added 3days ago";;
[label2 setNumberOfLines:1];
[cell.contentView addSubview:label2];
self.tagnumber++;
[self dismissMegaAnnoyingPopup];
return cell;
}
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//Hide Category view if not
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
//[self performSegueWithIdentifier:#"ShowGalleryDetail" sender:cell];
int rownumber = cell.tag;
//Here i get 0 for rownnumber and even if i use indexpath.row**
NSLog (#"Current Page for article is:%i", rownumber);
}
In your cellForRowAtIndexPath method, you set the tag of a UIImageView or the tag of a UILabel.
In your didSelectRowAtIndexPath method, you get the tag of the cell.
Either get the tag of the image view or label that is in the cell, or set the cell`s tag.

iOS: unable to change the height of UITableViewCell

I tried to follow this instruction to setup UITableView programatically, but the height of cell is unchanged. Here is the link for the instruction.
http://www.cimgf.com/2009/09/23/uitableviewcell-dynamic-height/
I have modified the code a little bit:
- (void)viewDidLoad{
[super viewDidLoad];
UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 460.0) style:UITableViewStylePlain];
self.myTB = tableView;
[tableView release];
UIView *view = [[UIView alloc] init];
[view addSubview:self.myTB];
self.view = view;
[view release];
self.myTB.dataSource = self;
items= [[NSMutableArray alloc] init];
[items addObject:#"Happiness is having a large, loving, caring, close-knit family in another city.\n\n\t\t-George Burns (1896 - 1996)"];
[items addObject:#"When I am abroad, I always make it a rule never to criticize or attack the government of my own country. I make up for lost time when I come home.\n\n\t\t-Sir Winston Churchill (1874 - 1965)"];
[items addObject:#"After two years in Washington, I often long for the realism and sincerity of Hollywood.\n\n\t\t-Fred Thompson, Speech before the Commonwealth Club of California"];
[items addObject:#"It is a profitable thing, if one is wise, to seem foolish.\n\n\t\t-Aeschylus (525 BC - 456 BC)"];
}
- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{
return [items count];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 100;
}
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell;
UILabel *label = nil;
cell = [tv dequeueReusableCellWithIdentifier:#"Cell"];
if (cell == nil){
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero ] autorelease];
label = [[UILabel alloc] initWithFrame:CGRectZero];
[label setLineBreakMode:UILineBreakModeWordWrap];
[label setMinimumFontSize:FONT_SIZE];
[label setNumberOfLines:0];
[label setFont:[UIFont systemFontOfSize:FONT_SIZE]];
[label setTag:1];
[[cell contentView] addSubview:label];
}
NSString *text = [items objectAtIndex:[indexPath row]];
CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);
CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
if (!label)
label = (UILabel*)[cell viewWithTag:1];
[label setText:text];
[label setFrame:CGRectMake(CELL_CONTENT_MARGIN, CELL_CONTENT_MARGIN, CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), MAX(size.height, 44.0f))];
return cell;
}
Here is what I get:
self.myTB.delegate = self;
Modify the following code to set the heights for individual cells.
(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 100;
}
Now you set it as 100 constantly, so the height doesn't change.
I don't think you need to init the UITableViewCell with a frame. I think just alloc] init] autorelease] should do the trick.
Just use:
self.myTB.rowHeight = 100;

How to set UIImage to UITableView Cell which calculates cell height dynamically based on text I input in UILabel?

I am creating UITableView, where each cell size will b calculated based on the text I input.
I am Calculating size of Cell in heighForRowAtIndexPath
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
NSString *text = [tableData objectAtIndex:[indexPath row]];
CGSize constraint = CGSizeMake(210.0f, 20000.0f);
size = [text sizeWithFont:[UIFont systemFontOfSize:12.0f] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
height = MAX(size.height, 44.0f);
return height + (CCM * 2);
}
this is how I am calculating height for each cell, now my question is - I want to add image to each cell like comment box? like this
Click here to see comment boxes I am looking for
You can see these kind of comment boxes
what I did is I made my image into two parts
first one has top part which is working well on every cell starting image is coming
now while fixing bottom part me facing problem
for small text in cell UILable its working well
when size of text in UILabel increased it's not getting properly adjusted
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *identifier = #"cell";
NSLog(#"index path %d", indexPath.row);
MyTableCell *cell = (MyTableCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil)
{
cell = [[[MyTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
[cell.cellBackgroundBottom setFrame:CGRectMake(75.0f, 92.0f, 228.0f, height + 25.0f)];
[cell.cellContent setText:(NSString*)[tableData objectAtIndex:[indexPath row]]];
[cell.cellContent sizeToFit];
CGRect theFrame = [cell.cellContent frame];
theFrame.size.width = 210.0f;
[cell.cellContent setFrame: theFrame];
return cell;
}
I have created one UITableView subclass naming MYTableCell where I have defined what all I need inside my each cell.
// Creating UILabel for cell content or comments block
cellContent = [[UILabel alloc]initWithFrame: CGRectMake( 90.0f, 15.0f, 210.0f, 60.0f)] ;
[cellContent setLineBreakMode:UILineBreakModeWordWrap];
cellContent.numberOfLines = 0;
[cellContent setMinimumFontSize:15.0f];
[cellContent setBackgroundColor:[UIColor clearColor]];
// [cellContent setTextColor:[UIColor colorWithRed:73.0f green:73.0f blue:73.0f alpha:1.0f]];
[cellContent setFont:[UIFont fontWithName:#"Helvetica" size:12.0f]];
cellContent.textAlignment = UITextAlignmentLeft;
[cellContent setTag:1];
[self addSubview:cellContent];
[cellContent release];
cellBackgroundTop = [[UIImageView alloc] initWithFrame:CGRectMake(60.0f, 5.0f, 243.0f, 13.5f)];
[cellBackgroundTop setImage:[UIImage imageNamed:#"comments.png"]];
[self addSubview:cellBackgroundTop];
[cellBackgroundTop release];
cellBackgroundBottom = [[UIImageView alloc] initWithFrame:CGRectZero];
[cellBackgroundBottom setImage:[UIImage imageNamed:#"Untitled-1_09.png"]];
[self addSubview:cellBackgroundBottom];
[cellBackgroundBottom release];
I got answer for my question
. This is what i have to do in my cellForRowAtIndexPath
NSString *text = [tableData objectAtIndex:[indexPath row]];
CGSize constraint = CGSizeMake(210.0f, 20000.0f);
CGSize size1 = [text sizeWithFont:[UIFont systemFontOfSize:12.0f] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
CGFloat height1 = MAX(size1.height, 44.0f);
[cell.cellBackgroundBottom setFrame:CGRectMake(75.0f, 18.0f, 228.0f, height1 + 10.0f)];

Resources