Here is the entire Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"DetailCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2
reuseIdentifier:CellIdentifier];
NSUInteger sectionIndex = [indexPath section];
NSUInteger rowIndex = [indexPath row];
NSDictionary *section = [self.sections objectAtIndex:sectionIndex];
NSArray *rows = [section objectForKey:#"rows"];
NSDictionary *row = [rows objectAtIndex:rowIndex];
cell.textLabel.text = [row objectForKey:#"label"];
cell.detailTextLabel.text = [[self.myManagedObject valueForKey:[row objectForKey:#"key"]] description];
return cell;
}
My question is about:
cell.textLabel.text = [row objectForKey:#"label"];
cell.detailTextLabel.text = [[self.myManagedObject valueForKey:[row objectForKey:#"key"]] description]; //This is NSDate
Why is this code using two different formats: objectForKey & valueForKey?
why is there not a need to call self.myManagedObject with objectForKey?
What's the purpose of description?
Why is this code using two different formats: objectForKey &
valueForKey?
why is there not a need to call self.myManagedObject with
objectForKey?
self.myManagedObject is an NSManagedObject. There is no objectForKey: method for NSManagedObject.
row is an NSDictionary type. objectForKey: is a dictionary method.
What's the purpose of description?
[self.myManagedObject valueForKey:[row objectForKey:#"key"]] should be returning an object which will contain a NSString type property as description.
They just as a single line. you can split up it to multiple lines as follows
YourCustomClass *customclassObj = [self.myManagedObject valueForKey:[row objectForKey:#"key"]];
cell.detailTextLabel.text = customclassObj.description;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
//create new cell
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
[tableView setRowHeight: 50.00];
UILabel *name=[[UILabel alloc]initWithFrame:CGRectMake(10, 5, 70, 30)];
name.text=#"Ajay";
[cell.contentView addSubview:name];
[name release];
// cell.selectionStyle = UITableViewCellSelectionStyleNone;
//cell.contentView.backgroundColor=[UIColor whiteColor];
UIButton *btn1=[[UIButton alloc]initWithFrame:CGRectMake(80, 5, 70, 30)];
//UIButton *btn1=[UIButton buttonWithType:UIButtonTypeRoundedRect];
//btn1.frame=CGRectMake(80, 5, 40, 30);
[btn1 setTitle:#"Name" forState:UIControlStateNormal];
[btn1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//[btn1 addTarget:self action:#selector(Nam:) forControlEvents:UIControlEventTouchUpInside];
btn1.backgroundColor=[UIColor greenColor];
[[btn1 layer]setCornerRadius:8.0f];
[[btn1 layer]setBorderWidth:1.0f];
[cell.contentView addSubview:btn1];
[btn1 release];
UILabel *add=[[UILabel alloc]initWithFrame:CGRectMake(10, 56, 70, 50)];
add.text=#"Biliya";
[cell.contentView addSubview:add];
[add release];
// cell.selectionStyle = UITableViewCellSelectionStyleNone;
//cell.contentView.backgroundColor=[UIColor whiteColor];
UIButton *btn2=[[UIButton alloc]initWithFrame:CGRectMake(80, 56, 70, 30)];
//UIButton *btn1=[UIButton buttonWithType:UIButtonTypeRoundedRect];
//btn1.frame=CGRectMake(80, 5, 40, 30);
[btn2 setTitle:#"Address" forState:UIControlStateNormal];
[btn2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//[btn1 addTarget:self action:#selector(Nam:) forControlEvents:UIControlEventTouchUpInside];
btn2.backgroundColor=[UIColor greenColor];
[[btn2 layer]setCornerRadius:8.0f];
[[btn2 layer]setBorderWidth:1.0f];
[cell.contentView addSubview:btn2];
[btn2 release];
return cell;
}
Related
I have a table view in which I'm loading some data i'm trying to make radio button on that data, but when i select any cell it does not deselect other it is working as a check box . I'm confused where i'm doing mistake, My code is this,
-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = #"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
radiobtn = [UIButton buttonWithType:UIButtonTypeCustom];
radiobtn.frame = CGRectMake(30, 60, 30, 30);
[radiobtn setImage:[UIImage imageNamed:#"circle.png"] forState:UIControlStateNormal];
[radiobtn setImage:[UIImage imageNamed:#"rights.png"] forState:UIControlStateSelected];
[radiobtn addTarget:self action:#selector(radiobtn:)
forControlEvents:UIControlEventTouchUpInside];
cell.accessoryView = radiobtn;
}
cell.textLabel.text = [dataArray objectAtIndex:indexPath.row];
cell.backgroundColor = [UIColor clearColor];
cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.font = [UIFont boldSystemFontOfSize:17];
UIView *selectionColor = [[UIView alloc] init];
selectionColor.backgroundColor = [UIColor colorWithRed:(0) green:(0) blue:(0) alpha:1];
cell.selectedBackgroundView = selectionColor;
cell.selectionStyle = UITableViewCellDragStateLifting;
return cell;
}
-(void)radiobtn:(UIButton *)sender
{
if([sender isSelected])
{
[sender setSelected:NO];
}
else
{
[sender setSelected:YES];
}
}
It is looking like this,
Try this.
-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = #"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
UIButton *radiobtn = [UIButton buttonWithType:UIButtonTypeCustom];
radiobtn.frame = CGRectMake(30, 60, 30, 30);
radiobtn.userInteractionEnabled = NO;
[radiobtn setImage:[UIImage imageNamed:#"circle.png"] forState:UIControlStateNormal];
[radiobtn setImage:[UIImage imageNamed:#"rights.png"] forState:UIControlStateSelected];
// [radiobtn addTarget:self action:#selector(radiobtn:) forControlEvents:UIControlEventTouchUpInside];
cell.accessoryView = radiobtn;
}
cell.textLabel.text = [dataArray objectAtIndex:indexPath.row];
cell.backgroundColor = [UIColor clearColor];
cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.font = [UIFont boldSystemFontOfSize:17];
UIView *selectionColor = [[UIView alloc] init];
selectionColor.backgroundColor = [UIColor colorWithRed:(0) green:(0) blue:(0) alpha:1];
cell.selectedBackgroundView = selectionColor;
cell.selectionStyle = UITableViewCellDragStateLifting;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
UIButton *button = (UIButton *)cell.accessoryView;
button.selected = YES;
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
UIButton *button = (UIButton *)cell.accessoryView;
button.selected = NO;
}
I'm creating a UISwitch programmatically in one of the tableview datasource function(cell for row at index). when I'm scrolling the table view, the OFF state switches are malfunctioned(UI) two rounds appeared. Attaching the screenshot of the switch.
Appreciate your help!
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell" forIndexPath:indexPath];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
UILabel *title = (UILabel*)[cell viewWithTag:80];
UILabel *description = (UILabel*)[cell viewWithTag:81];
UIView *innerView = (UIView *)[cell viewWithTag:82];
innerView.layer.borderColor=[[UIColor colorWithRed:229/255.0f green:229/255.0f blue:229/255.0f alpha:1.0] CGColor];
innerView.layer.borderWidth = 2.0f;
NSDictionary *displayDict = scenarioListsArray[indexPath.row];
title.text =[displayDict objectForKey:#"name"];
description.text = [displayDict objectForKey:#"description"];
UISwitch *myswitch = [[UISwitch alloc]initWithFrame:CGRectMake(cell.contentView.frame.size.width-60, (cell.contentView.frame.size.height/2)-20 , 100, 100)];
myswitch.onTintColor = [UIColor colorWithRed:25/255.0f green:122/255.0f blue:66/255.0f alpha:1];
[cell.contentView addSubview:myswitch];
myswitch.tag = indexPath.row;
[myswitch addTarget:self action:#selector(cellButtonClickAction:) forControlEvents:UIControlEventValueChanged];
if ([[displayDict objectForKey:#"status"] isEqualToString:#"ACTIVE"]) {
[myswitch setOn:YES animated:YES];
}
else
{
[myswitch setOn:NO animated:YES];
}
return cell;
}
I have faced the same issue and fixed with following code before creating switch
for(UIView *subView in cell. contentView.subviews){
if ([subView isKindOfClass:[UISwitch class]]) {
[subView removeFromSuperview];
}
}
Or
static NSString *TableIdentifier = #"YourCellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TableIdentifier];
//place your all UI elements code here.
}
I have updated your code, try this will work for you,
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell" forIndexPath:indexPath];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
UILabel *title = (UILabel*)[cell viewWithTag:80];
UILabel *description = (UILabel*)[cell viewWithTag:81];
UIView *innerView = (UIView *)[cell viewWithTag:82];
innerView.layer.borderColor=[[UIColor colorWithRed:229/255.0f green:229/255.0f blue:229/255.0f alpha:1.0] CGColor];
innerView.layer.borderWidth = 2.0f;
NSDictionary *displayDict = scenarioListsArray[indexPath.row];
title.text =[displayDict objectForKey:#"name"];
description.text = [displayDict objectForKey:#"description"];
UISwitch *myswitch = [cell.contentView viewWithTag:indexPath.row+597];
if(mySwitch == nil){
myswitch = [[UISwitch alloc]initWithFrame:CGRectMake(cell.contentView.frame.size.width-60,(cell.contentView.frame.size.height/2)-20 , 100, 100)];
[cell.contentView addSubview:myswitch];
[myswitch addTarget:self action:#selector(cellButtonClickAction:) forControlEvents:UIControlEventValueChanged];
}
myswitch.onTintColor = [UIColor colorWithRed:25/255.0f green:122/255.0f blue:66/255.0f alpha:1];
myswitch.tag = indexPath.row+597; //597 is extra number added to tag
if ([[displayDict objectForKey:#"status"] isEqualToString:#"ACTIVE"]) {
[myswitch setOn:YES animated:YES];
}
else
{
[myswitch setOn:NO animated:YES];
}
return cell;
}
I have a custom table view in my app which has button in each row.
I want to change button background image when flag of that cell is i'1'(check if statement in code.).
it is successfully executing if statements.
Just the button's background image is not changing.
Here is my code
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:#"cell"];
cell= [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"cell"]autorelease];
if(tableView == tablePatchFilter)
{
cell.textLabel.text=[filterPatchName objectAtIndex:indexPath.row];
}
else
{
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text=[displayItems objectAtIndex:indexPath.row];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UILabel *typeLabel = [[[UILabel alloc]init]autorelease];
typeLabel.backgroundColor = [UIColor clearColor];
typeLabel.text = [displayItemsType objectAtIndex:indexPath.row];
typeLabel.textAlignment = NSTextAlignmentLeft;
typeLabel.font=[UIFont fontWithName:MyFont size:17.f];
typeLabel.frame = CGRectMake(300,2.0f,250,50);
[cell addSubview:typeLabel];
UILabel *typeLabel1 = [[[UILabel alloc]init]autorelease];
typeLabel1.backgroundColor = [UIColor clearColor];
typeLabel1.text = [displayItemPatch objectAtIndex:indexPath.row];
typeLabel1.textAlignment = NSTextAlignmentLeft;
typeLabel1.font=[UIFont fontWithName:MyFont size:17.f];
typeLabel1.frame = CGRectMake(550,2.0f,250,50);
[cell addSubview:typeLabel1];
UILabel *typeLabel2 = [[[UILabel alloc]init]autorelease];
typeLabel2.backgroundColor = [UIColor clearColor];
typeLabel2.font=[UIFont fontWithName:MyFont size:17.f];
typeLabel2.text = [displayItemclass objectAtIndex:indexPath.row];
typeLabel2.textAlignment = NSTextAlignmentLeft;
typeLabel2.frame = CGRectMake(730,2.0f,250,50);
[cell addSubview:typeLabel2];
int selectedSegment = mainSegment.selectedSegmentIndex;
if(selectedSegment == 0)
{
for(int i = 0;i<[displayFlag count];i++)
{ UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.tag=indexPath.row;
[btn addTarget:self
action:#selector(takeSignature:)
forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:btn];
NSMutableString *pathhh= [NSMutableString stringWithFormat:#"%#",[displayFlag objectAtIndex:i]];
NSLog(#"XXXXXXXXXXXXXXXXXXXXXXXXXX%#",pathhh);
if([pathhh isEqualToString:#"1"])
{
NSLog(#"in IFFFFFFF%#",pathhh);
btn.frame = CGRectMake(850,1, 50, 50);
[btn setBackgroundImage:[UIImage imageNamed:#"signature.png"]
forState:UIControlStateNormal];
}
else
{
NSLog(#"in ELSSSSSSSSSS %#",pathhh);
btn.frame = CGRectMake(850,1, 50, 50);
[btn setBackgroundImage:[UIImage imageNamed:#"add.png"]
forState:UIControlStateNormal];
}
}
/*
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(850,1, 50, 50);
[btn setBackgroundImage:[UIImage imageNamed:#"signature.png"]
forState:UIControlStateNormal];
[btn addTarget:self
action:#selector(takeSignature:)
forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:btn];
*/
}
}
cell.textLabel.font=[UIFont fontWithName:MyFont size:17.f];
return cell;
}
In your implementation every time you are creating new cell, after getting cell from "dequeueReusableCellWithIdentifier" you have to check for cell if it nil than only create new cell using "alloc-init".
The better implementation of the particular senireo is to take a custom UITableViewCell.
The following stategie you should follow.
In the custom cell create the outlet for label 1, 2 and 3, than set the test in cellForRowatIndexPath.
Create a property of NSMutableArray in the custom cell class.
After getting the cell from "dequeueReusableCellWithIdentifier" check if cell is nil than only create the buttons and add all the buttons in the NSMutableArray created in step 2.
take the buttons from the NSMutableArray and that apply the condition for setting the images.
Please see the below code:
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if(tableView == tablePatchFilter)
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell"];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"cell"];
}
cell.textLabel.text=[filterPatchName objectAtIndex:indexPath.row];
return cell;
} else {
CustomTableViewCell *cell = (CustomTableViewCell*)[tableView dequeueReusableCellWithIdentifier:#"cell"];
if (!cell) {
cell = [[CustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"cell"];
int selectedSegment = mainSegment.selectedSegmentIndex;
if(selectedSegment == 0) {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.tag=indexPath.row;
[btn addTarget:self action:#selector(takeSignature:) forControlEvents:UIControlEventTouchUpInside];
[cell.buttonArray addObject:btn];
}
}
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text=[displayItems objectAtIndex:indexPath.row];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.label1.text = [displayItemsType objectAtIndex:indexPath.row];
cell.label2.text = [displayItemPatch objectAtIndex:indexPath.row];
cell.label3.text = [displayItemclass objectAtIndex:indexPath.row];
for (UIButton *btn in cell.buttonArray) {
NSMutableString *pathhh= [NSMutableString stringWithFormat:#"%#",[displayFlag objectAtIndex:i]];
if([pathhh isEqualToString:#"1"]) {
btn.frame = CGRectMake(850,1, 50, 50);
[btn setBackgroundImage:[UIImage imageNamed:#"signature.png"] forState:UIControlStateNormal];
} else {
btn.frame = CGRectMake(850,1, 50, 50);
[btn setBackgroundImage:[UIImage imageNamed:#"add.png"] forState:UIControlStateNormal];
}
}
return cell;
}
}
I added UIButton to each uitableview row but when i nedd reloadData, uibutton is 0x0000. Can you give me any suggestions? Thanks much.
I used this code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
/*NSString *CellIdentifier = [NSString stringWithFormat:#"%d,%d",indexPath.section,indexPath.row];
// NSString *CellIdentifier = #"cell";
UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{*/
NSString *CellIdentifier = [NSString stringWithFormat:#"%d,%d",indexPath.section,indexPath.row];
UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
UILabel *pricelabel = [[UILabel alloc] initWithFrame:CGRectMake(80, 0, 80, 30)];
pricelabel.backgroundColor = [UIColor clearColor];
pricelabel.font = [UIFont fontWithName:#"Helvetica" size:16];
pricelabel.font = [UIFont boldSystemFontOfSize:16];
pricelabel.textColor = [UIColor darkGrayColor];
pricelabel.tag = 3000;
//pricelabel.hidden = YES;
pricelabel.textAlignment = NSTextAlignmentRight;
[cell.contentView addSubview: pricelabel];
[pricelabel release];
UIButton * market = [[UIButton alloc] init];;
[market setFrame:CGRectMake(200, 6, 30, 30)];
market.tag = 4000;
[market addTarget:self action:#selector(marketPressedAction:) forControlEvents:UIControlEventTouchDown];
// [market setTag:indexPath.row];
[cell.contentView addSubview:market];
}
if([priceNewArray count]> 0)
{
UILabel *pricelbl = (UILabel*)[cell.contentView viewWithTag:3000];
pricelbl.text =[NSString stringWithFormat:#"$%#",[priceNewArray objectAtIndex:indexPath.row]];
if ([sellingArray count]>0) {
if([[sellingArray objectAtIndex:indexPath.row] isEqualToString:#"2"]){
pricelbl.hidden = NO;
}
else if([[sellingArray objectAtIndex:indexPath.row] isEqualToString:#"0"]){
pricelbl.hidden = YES;
}
}
}
UIButton *marketButton = (UIButton*)[cell.contentView viewWithTag:4000];
[marketButton setTag:indexPath.row];
if([sellingArray count]>0)
{
NSLog(#"sellingArray %#",sellingArray);
if([[sellingArray objectAtIndex:indexPath.row] isEqualToString:#"0"]) // nothing
{
[marketButton setSelected:NO];
[marketButton setImage:[UIImage imageNamed:#"Marketplace.png"] forState:UIControlStateNormal];
marketButton.enabled = YES;
}
else if([[sellingArray objectAtIndex:indexPath.row] isEqualToString:#"2"]) // marketplace
{
[marketButton setSelected:YES];
[marketButton setImage:[UIImage imageNamed:#"MarketplaceSelect.png"] forState:UIControlStateNormal];
marketButton.enabled = YES;
}
}
_tableView.contentInset = UIEdgeInsetsMake(0, 0, 100, 0);
return cell;
}
I used above code, when reloadData, data of Price label is changed fine but marketbutton can not changed image. I debug after call [_tableview reloadData];, marketButton is 0x0000 .
I think your comparison is not correct. You are trying to compare integer with string.
If i asumed correct then try something like this.
int sellingPrice=0;
if([[sellingArray objectAtIndex:indexPath.row] isEqualToString: [NSString stringWithFormat:#"%i",sellingPrice]]) // nothing
sellingPrice=2;
else if([[sellingArray objectAtIndex:indexPath.row] isEqualToString:[NSString stringWithFormat:#"%i",sellingPrice]]) // marketplace
use single CellIdentifier for cell when using same designs for cell,it used to reuse tableview cells
NSString *CellIdentifier = #"Cell"
please remove this code [marketButton setTag:indexPath.row]; you not want to change tag for cell,you not set tag for identifier for UIButton, change this two thinks your code will work
I have this issue on adding a last cell row to my tableView.
Can someone please tell me what's wrong with my code as the last row appears but it also appears elsewhere when the table is scrolled down. Any help will be greatly appreciated, Thank you. Here's my code:
#interface ViewOrderViewController : UIViewController < UITableViewDataSource, UITableViewDelegate> {
IBOutlet UITableView *tabView;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [appDelegate.vieworderArray count] + 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:#"Cell"];
}
NSUInteger row = [indexPath row];
if(row == [appDelegate.vieworderArray count] ) {
cell.textLabel.text = [NSString stringWithFormat:#"extra cell"];
}else{
Vieworder *vieworderObj = (Vieworder *)[appDelegate.vieworderArray objectAtIndex:indexPath.row];
NSMutableString *mcmenuNameQuantity = [NSMutableString stringWithFormat:#"%# X %i", vieworderObj.mcmenu_name, vieworderObj.mcmenu_quantity];
UILabel *mcmenuLabel = [[UILabel alloc] initWithFrame:CGRectMake(45, 0, 200, 25)];
[mcmenuLabel setFont:[UIFont systemFontOfSize:13.0f]];
[mcmenuLabel setText:mcmenuNameQuantity];
UILabel *mcmenuPricexquantity = [[UILabel alloc] initWithFrame:CGRectMake(213, 0, 60, 25)];
[mcmenuPricexquantity setFont:[UIFont systemFontOfSize:12.0f]];
mcmenuPricexquantity.textAlignment = NSTextAlignmentRight;
NSMutableString *mcmenuPriceQuantityString = [NSMutableString stringWithFormat:#"%0.2f", vieworderObj.mcmenu_total_price];
mcmenuPricexquantity.numberOfLines = 2;
[mcmenuPricexquantity setText:mcmenuPriceQuantityString];
UIButton *deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
deleteButton.frame = CGRectMake(12.0f, 0.0f, 25.0f, 25.0f);
deleteButton.tag = indexPath.row;
UIImage* imageDelete = [[UIImage alloc] init];
imageDelete = [UIImage imageNamed:[NSString stringWithFormat:#"vieworder_delete.png"]];
[deleteButton setImage:imageDelete forState:UIControlStateNormal]
[deleteButton addTarget:self action:#selector(performExpand:) forControlEvents:UIControlEventTouchUpInside];
UIButton *editButton = [UIButton buttonWithType:UIButtonTypeCustom];
editButton.frame = CGRectMake(280.0f, 0.0f, 25.0f, 25.0f);
UIImage* imageEdit = [[UIImage alloc] init];
imageEdit = [UIImage imageNamed:[NSString stringWithFormat:#"vieworder_edit.png"]];
[editButton setImage:imageEdit forState:UIControlStateNormal];
editButton.tag = indexPath.row;
[editButton addTarget:self action:#selector(buttonClicked2:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:deleteButton ];
[cell.contentView addSubview:mcmenuLabel];
[cell.contentView addSubview:mcmenuPricexquantity ];
[cell.contentView addSubview:editButton ];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
}
return cell;
}
Use simplest code first
arr=#[#"A",#"B",#"C",#"D",#"E",#"F",#"A",#"B",#"C",#"D",#"E",#"F",#"A",#"B",#"C",#"D",#"E",#"F",#"A",#"B",#"C",#"D",#"E",#"F",#"A",#"B",#"C",#"D",#"E",#"F",#"A",#"B",#"C",#"D",#"E",#"F"];
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [arr count]+1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:#"cell"];
if (cell==nil) {
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"cell"];
}
cell.textLabel.text=(indexPath.row==arr.count)?#"End of Row":arr[indexPath.row];
return cell;
}
If it is working then then there should be some problem with your else condition where you are adding multiple subviews to cell.ContentView.