uitableview - Adding last row cell (that is not part of sqlite table) on tableView -


i have issue on adding last cell row tableview. can please tell me what's wrong code last row appears appears elsewhere when table scrolled down. appreciated, thank you. here's 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 working then there should problem else condition adding multiple subviews cell.contentview.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -