Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView delegates are not called

I have a tableview with external delegate controller. Despite content table view array is well populated, and
numberOfSectionsInTableView: and -tableView: numberOfRowsInSection: are called,
but-tableView: cellForRowAtIndexPath: is not called.

Issued table view is set in that ways:

CompeticionViewController.h

....

@property (retain, nonatomic) IBOutlet UITableView *calendarioTable;
@property (strong, nonatomic)  calendarioViewController *calendarioController;

....

calendarioTable = [[UITableView alloc] init];

            calendarioController  = [[calendarioViewController alloc] init];

            [calendarioTable setDelegate:calendarioController];

            [calendarioTable setDataSource:calendarioController];

            calendarioController.calendarioArray = [[NSMutableArray alloc] init];

            [calendarioController.calendarioArray addObjectsFromArray: self.calendarioarray];

            [calendarioTable reloadData];

EDITED:

calendarioViewController.m

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

    return 1;
}

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

    return [calendarioArray count];

}

Many thanks

like image 819
theomen Avatar asked May 17 '12 11:05

theomen


People also ask

What are delegate and datasource methods of UITableView?

Datasource methods are used to generate tableView cells,header and footer before they are displaying.. Delegate methods provide information about these cells, header and footer along with other user action handlers like cell selection and edit..

What is tableView delegate?

func tableView(UITableView, willDisplay: UITableViewCell, forRowAt: IndexPath) Tells the delegate the table view is about to draw a cell for a particular row. func tableView(UITableView, indentationLevelForRowAt: IndexPath) -> Int. Asks the delegate to return the level of indentation for a row in a given section.

What is UITableView?

UITableView manages the basic appearance of the table, but your app provides the cells ( UITableViewCell objects) that display the actual content. The standard cell configurations display a simple combination of text and images, but you can define custom cells that display any content you want.

What class does UITableView inherit from?

The tableview is the instance of the UITableView class, which inherits the UIScrollView class. We will discuss UIScrollView in the upcoming chapters of this tutorial. In iOS applications, whenever we need to display the single column containing vertically scrolling content, we use tableview.


2 Answers

In .xib file link delegate and datasource with File's owner or write

tableview.delegate=self

tableview.datasource=self; 
like image 192
Rock Avatar answered Oct 09 '22 08:10

Rock


You have used IBOulet for tableview then why are u allocating it as its not need memory already allocated.

Now check in xib of your view controller that tableview is binded and its delegate and datasource provided to file owner.

-----------------------------------------OR------------------------------------------------

add this line in viewDidLoad method

yourtableview.delegate=self

yourtableview.datasource=self; 

Now After using IBOulet for tableview you will have bind it with file owner and ViewController interface implements both the <UITableViewDelegate> and <UITableViewDataSource> protocols

Now check array you are providing to tableview has content in it

Edit : Add OR code and done formatting

like image 1
Paresh Navadiya Avatar answered Oct 09 '22 08:10

Paresh Navadiya