I am using this code to display all the rows from database, but when the tableview loads only the last row shows up.. what am I doing wrong. Please help!!
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Event" inManagedObjectContext:managedObjectContext];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entity];
NSError *error;
NSMutableArray *mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
if (!mutableFetchResults)
{
NSLog(@"Cant Fetch");
}
//compare fetched data with user input abd login if match
for(Event *ev in mutableFetchResults)
{
NSString *cellValue=[ev VidField];
NSString *cellValue1=[ev ImgField];
NSLog(@"%@",cellValue);
NSLog(@"%@",cellValue1);
[cell.textLabel setText:cellValue];
cell.image = [UIImage imageNamed:cellValue1];
}
return cell;
}
you should do like this;
in .h file;
in .m file;
i think this will work.