1

I have a Master-Detail application. When the user selects a row in the Master table(MasterViewController),I want to open another UITableViewController (DocumentViewController) and display data here(not in the Detail view).

When I run the application,"numberOfSectionsInTableView" for DocumentViewController is called but "cellForRowAtIndexPath" is not called.

The code in DocumentViewController.m is:

 - (void)viewDidLoad
{
  [super viewDidLoad];
  [docTable setDataSource:self];
  [docTable setDelegate:self];

EDViPadDocSyncService *service = [[EDViPadDocSyncService alloc]init];
EDVCategory *cat = [EDVCategory alloc];
cat.categoryId = [catId intValue];
[service getDocsByCatId:self action:@selector(getDocsByCatIdHandler:) category:cat];

[self.docTable reloadData];
}

 - (void) getDocsByCatIdHandler: (id)value {
      //snip......
      [docTable reloadData];
}

- (void)viewDidUnload
{
   [super viewDidUnload];
}


 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
   return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
   return [self.myDocList count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   DocumentCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DocumentCell"];
   if (cell == nil)
   {
      cell = [[[DocumentCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"DocumentCell"] autorelease];
   }
NSLog(@"cell text=%@",[self.myDocList objectAtIndex:indexPath.row]);
cell.lblDocName.text = [self.myDocList objectAtIndex:indexPath.row];
return cell;

}

Thanks for the help.

EDIT:- I have set the delegate and datasource properties for the table.The table is declared as "@property (nonatomic,retain) IBOutlet UITableView *docTable;" in the DocumentViewController.h. I have tried using 'viewwillappear' as well as 'initwithstyle' but these doesn't seem to work either.

The iOSDev
  • 5,237
  • 7
  • 41
  • 78
user1550951
  • 369
  • 2
  • 9
  • 26
  • 2
    have you linked your doctable from xib? if not then do it.and also call [self.docTable reloadData]; it from view will appear. – swetank Aug 20 '12 at 04:34
  • Please check out that in `tableView:numberOfRowsInSection:` this method what is returned byt the `return` statement does it is greater then **0** – The iOSDev Aug 20 '12 at 05:44
  • @swetank:- noobish question,shud i call 'viewWillAppear' in MasterTableVC or DocumentViewController? – user1550951 Aug 20 '12 at 05:56
  • @AalokParikh:- it's returning 1. – user1550951 Aug 20 '12 at 05:58
  • so the method must be called for once only :) and yes at the time of `return cell;` statement does the cell is created properly or it is just `nil`. Just check it out that also :) – The iOSDev Aug 20 '12 at 06:01
  • Oh and what does the `cell.lblDocname.text` means ?? Does you have used custom cell ?? :) – The iOSDev Aug 20 '12 at 06:03
  • @AalokParikh:- "cellForRowAtIndexPath" is not getting called, and that's the problem.Yes,its a custom cell.I have linked 'lblDocname' to the cell. Any other suggestions? – user1550951 Aug 20 '12 at 06:03
  • As I have mentioned check out that at the `return cell;` statement cell does not `nil` or have created properly and the `lblDocName` is not available by default in any cell type other then your custom cell :) and if it is the case you have to check that out the custom cell is properly assigned in the XIB and all the delegates and IBOutlates are set properly :) – The iOSDev Aug 20 '12 at 06:08
  • @AalokParikh:How can i check if "return cell" statement cell does not return "nil" when the function itself is **not** getting called?I have done all the properties,linked everything in the storyboard. – user1550951 Aug 20 '12 at 07:32
  • ok then before return statement just put NSLog statement for printing the cell using %@ :) and see what is shows and to see that the cellForRowAtIndexPath is called place any NSLog line and with just any text to print will clear that the method is called or not :) – The iOSDev Aug 20 '12 at 07:38

0 Answers0