DISPALYING DATA FROM NSARRAY TO TABLE VIEW

Nigel Bunyan

Total Post:20

Points:140
Posted by  Nigel Bunyan
 815  View(s)
Ratings:
Rate this:

I am new in iOS and making a lightweight application. I am taking two textfield entries from one view controller and storing them in NSDictionary. I am transferring those data in NSArray. Now I want to display those data from NSArray to table view. I am using this line of code:

cell.textLabel.text = [self.myArray objectAtIndex:indexPath.row];

But my app is crashing when cursor comes at this line. Help is appreciated. Thanks in advance.

 

  1. Tarun Kumar

    Post:214

    Points:1642
    Re: dispalying data from NSarray to table view

    For UITableView you have to define at least 2 methods:

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:

    (NSIndexPath *)indexPath

    It seems your method numberOfRowsInSection is not implemented.

    Try to add this:

    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: {
    

        return [self.myArray count];

    }

    Of course your ViewController have to be delegated for UITableViewDataSource and UItableViewDelegate.

      Modified On Aug-12-2015 10:52:19 PM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!