Advertise with us

dispalying data from NSarray to table view

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.

 

Last updated:8/12/2015 10:51:29 PM

1 Answers

Tarun Kumar
Tarun Kumar

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.

Answer