Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It cannot look exactly like you want it to, because tables in MS Excel and on the iPhone are different.</p> <p>The table view on iOS has two items which you can configure to show data -- a datasoure and a delegate. </p> <p>If you can fetch all the data from MS Excel in such a way that you can access any particular data just by knowing its row and column, then that data can be shown in your table view.</p> <p>In a table view there is a concept of <code>NSIndexPath</code>, which is a structure of row numbers and corresponding section number. Now let's suppose that there is situation that your Excel document has records of one hundred students and each record has three fields: name, age, sex. In this situation you'll make a table view with one hundred sections and three rows for each section.</p> <p>Now suppose you have a view controller named <code>myViewController</code> to show this table view, named <code>myTableView</code>:</p> <pre><code>-(void)viewDidLoad { myTableView.datasource = self; myTableView.delegate = self; } </code></pre> <p>Now before you can do that you need to do the following in the MyViewController.h file</p> <pre><code>@interface MyViewController: UIViewController &lt;UITableViewDataSource, UITableViewDelegate&gt; { </code></pre> <p>Now suppose you have an array named <code>allStudents</code> containing objects of class <code>Student</code> which has three properties:</p> <pre><code>NSString * name; NSUInteger * age; BOOL male; // yes if sex is male else NO </code></pre> <p>Now you need to implement the table view datasource and delegate methods:</p> <pre><code>-(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; } </code></pre> <p>You can access different properties of your table view to make it behave differently.</p> <p>I hope this helped you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload