mercredi 25 mars 2015

Adding a UITableVIew on to a View

When a user clicks on a Button, i slide in a UIView (This UIVIew is created via a XIB file).


I have added a TableView to this XIB file and connected the datasource and delegate as well. See image below:


enter image description here


In the View class i have added the following method.



-(id)initWithFrame:(CGRect)frame{

self = [super initWithFrame:frame];

[self addSubview:self. tablev];

}


In the Header file i have the following code.



@interface MyView : UIView <UITableViewDataSource,UITableViewDelegate>


The code for the UIViewController class. There's a button in this class, and when the user clicks on it the UIView will show. The code that will be executed when the button is clicked.



fv = [[FView alloc] initWithFrame:cell.bounds];

[self.view addSubview:fv];

[self.view addSubview: fv];


The view pops up perfectly with the tableview. However, the content on the tableview are not populated. When i debugged the code i found out that the delegate methods are not called. How can i solve this?



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

MyCell

*cell = [tableView dequeueReusableCellWithIdentifier:@"c" forIndexPath:indexPath];

if (cell == nil)

{

cell = [[MyCell

alloc] initWithStyle:UITableViewCellStyleSubtitle

reuseIdentifier:@"c"];

}

cell.la.text=@"hiiiii";



Aucun commentaire:

Enregistrer un commentaire