iphone - Table view basics and appearance like MS Excel -


i new objective-c programming. please me understand how insert data table view visual style similar ms excel.

it cannot want to, because tables in ms excel , on iphone different.

the table view on ios has 2 items can configure show data -- datasoure , delegate.

if can fetch data ms excel in such way can access particular data knowing row , column, data can shown in table view.

in table view there concept of nsindexpath, structure of row numbers , corresponding section number. let's suppose there situation excel document has records of 1 hundred students , each record has 3 fields: name, age, sex. in situation you'll make table view 1 hundred sections , 3 rows each section.

now suppose have view controller named myviewcontroller show table view, named mytableview:

-(void)viewdidload {      mytableview.datasource = self;      mytableview.delegate = self; } 

now before can need following in myviewcontroller.h file

@interface myviewcontroller: uiviewcontroller <uitableviewdatasource, uitableviewdelegate> { 

now suppose have array named allstudents containing objects of class student has 3 properties:

nsstring * name;  nsuinteger * age;  bool male; // yes if sex male else no 

now need implement table view datasource , delegate methods:

-(nsinteger)numberofsectionsintableview:(uitableview *)tableview {      return [allstudents count]; }  -(nsinteger)tableview:(uitableview *)tableview  numberofrowsinsection:(nsinteger)section  {     return 3; }  - (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] autorelease];     }      student * current = [allstudents objectatindex:nsindexpath.section];     cell.textlabel.text = current.name;     if( current.male ) {         cell.detailtextlabel.text = [nsstring stringwithformat:@"%dyr m",current.age];     } else {         cell.detailtextlabel.text = [nsstring stringwithformat:@"%dyr f",current.age];     }       return cell; } 

you can access different properties of table view make behave differently.

i hope helped you.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -