0

My cellForRowAtIndexPath doesn't get updated after i return from a detail view controller.

HomeViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.title  =@"Welcome";

[eventsTable registerNib:[UINib nibWithNibName:@"EventCell" bundle:nil] forCellReuseIdentifier:@"EventCell"];

//filtering process from current date
[self fetchUsersForType:1];
[eventsTable reloadData];

// Configure the bar button Items..
UIBarButtonItem *filterButton = [[UIBarButtonItem alloc]initWithTitle:@"Filter" style:UIBarButtonItemStylePlain target:self action:@selector(filterTapped:)];
UIBarButtonItem *addButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addTapped:)];
self.navigationItem.leftBarButtonItem = filterButton;
self.navigationItem.rightBarButtonItem = addButton;

refreshControl= [[UIRefreshControl alloc]init];
[eventsTable addSubview:refreshControl];

//testing

    [refreshControl addTarget:self action:@selector(reloadTable) forControlEvents:UIControlEventValueChanged];  //performing async operation here





[bottomView setFrame:CGRectMake(0, self.view.frame.size.height-69, 320, 69)];
 }

tableview datasource methods

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

return  [self.eventsArray count];//1;//[sectionInfo numberOfObjects];
 }

 // Customize the appearance of table view cells.
 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath   *)indexPath
 {

 static NSString *CellIdentifier = @"EventCell";

//testing


EventCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
PersonEvent *currentEvent = [self.eventsArray objectAtIndex:indexPath.row];
[cell configureForEvent:currentEvent];
   return cell;

 }

ViewDidAppear

  -(void)viewDidAppear:(BOOL)animated
 {
[super viewDidAppear:animated];



[[NSNotificationCenter defaultCenter]removeObserver:self];
  [self reloadTable];
 }

- (void)reloadTable
{
NSLog(@"Reloading table view for the new contacts .");
[self fetchUsersForType:currentFilterIndex];
[eventsTable reloadData];
[refreshControl endRefreshing];
  NSLog(@"Observer finished.");
}

Since i have used a refresh control it updates after i refresh twice, what is the problem?

I put breakpoints too,but cellForRowAtIndexPath gets called only the first time, but when i select a particular row and enter a detail view controller and come back my cellForRowAtIndexPath doesn't get called.

Mayur Prajapati
  • 5,454
  • 7
  • 41
  • 70
vin
  • 1,258
  • 5
  • 20
  • 33
  • Did you check your self.eventsArray count when you come back from the details view controller ? – danypata May 13 '13 at 07:29
  • Where is the implementation of reloadTable? – Stavash May 13 '13 at 07:32
  • Did you check if [self reloadTable] in your viewDidAppear is called? I am assuming reloadTable just calls reloadData on the tableview? – lostInTransit May 13 '13 at 07:32
  • Try doing reload table in viewWillAppear and remove [eventsTable reloadData]; from viewDidLoad. Why are you reloading table again and again?? – Divyu May 13 '13 at 07:33
  • @lostInTransit i have added reloadTable method – vin May 13 '13 at 07:47
  • 1
    u can make sure that `eventsTable` variable in `- (void)reloadTable` is not `nil` – Saurabh Passolia May 13 '13 at 08:00
  • thanks..i had assigned eventsTable nil in viewDidDisappear,so it was taking null value,is there any way i can make tableview nil because its causing memory issue,in ios 6 i cant use viewdidunload – vin May 13 '13 at 08:06

0 Answers0