Parse Pagination Not Working - ios

In my app, I use Parse. I have it set up like this:
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
// The className to query on
self.parseClassName = #"Prayers";
// Whether the built-in pull-to-refresh is enabled
self.pullToRefreshEnabled = YES;
// Whether the built-in pagination is enabled
self.paginationEnabled = YES;
// The number of objects to show per page
self.objectsPerPage = 20;
}
return self;
}
- (PFQuery *)queryForTable {
PFQuery *query = [PFQuery queryWithClassName:#"Prayers"];
// If no objects are loaded in memory, we look to the cache first to fill the table
// and then subsequently do a query against the network.
if (self.objects.count == 0) {
query.cachePolicy = kPFCachePolicyCacheThenNetwork;
}
[query orderByDescending:#"createdAt"];
return query;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
object:(PFObject *)object
{
static NSString *CellIdentifier = #"Cell";
Cell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[Cell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
self.theObject = object;
BOOL anony = [object[#"Anonymous"] boolValue];
if (!anony) {
NSString *names = [[object[#"FirstName"] stringByAppendingString:#" "] stringByAppendingString:object[#"LastName"]];
cell.profileName.text = names;
cell.contentLabel.text = object[#"Request"];
cell.firstName = object[#"FirstName"];
cell.lastName = object[#"LastName"];
cell.iostoken = object[#"DeviceID"];
cell.request = names;
cell.prayerObject = object;
PFFile *thumbnail = object[#"ProfilePic"];
cell.profilePic.image = [UIImage imageNamed:#"AppIcon60x60#2x.png"];
/*[cell.commentButton addTarget:self action:#selector(didTapCommentButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[cell.commentButton setTitle:#"Share" forState:UIControlStateNormal];
[cell.commentButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[cell.commentButton setTitleColor:[UIColor greenColor] forState:UIControlStateHighlighted];*/
[thumbnail getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
UIImage *thumbnailImage = [UIImage imageWithData:imageData];
UIImageView *thumbnailImageView = [[UIImageView alloc] initWithImage:thumbnailImage];
cell.profilePic.image = thumbnailImage;
}];
NSString *dates = object[#"dateMade"];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:#"MMM_dd_yyyy"];
NSDate *datefromstring = [formatter dateFromString:dates];
NSDateFormatter *formatter2 = [[NSDateFormatter alloc] init];
[formatter2 setDateFormat:#"MMM dd, yyyy"];
cell.dateLabel.text = [formatter2 stringFromDate:datefromstring];
UIFont *cellFont = [UIFont fontWithName:#"Verdana-Bold" size:15];
UIFont *cellFont2 = [UIFont fontWithName:#"Verdana-Bold" size:12];
}
else {
// Configure the cell to show todo item with a priority at the bottom
cell.profileName.text = object[#"Title"];
cell.contentLabel.text = object[#"Request"];
cell.firstName = object[#"FirstName"];
cell.lastName = object[#"LastName"];
cell.iostoken = object[#"DeviceID"];
cell.request = object[#"Title"];
cell.prayerObject = object;
PFFile *thumbnail = object[#"ProfilePic"];
cell.profilePic.image = [UIImage imageNamed:#"AppIcon60x60#2x.png"];
[thumbnail getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
UIImage *thumbnailImage = [UIImage imageWithData:imageData];
UIImageView *thumbnailImageView = [[UIImageView alloc] initWithImage:thumbnailImage];
cell.profilePic.image = thumbnailImage;
}];
NSString *dates = object[#"dateMade"];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:#"MMM_dd_yyyy"];
NSDate *datefromstring = [formatter dateFromString:dates];
NSDateFormatter *formatter2 = [[NSDateFormatter alloc] init];
[formatter2 setDateFormat:#"MMM dd, yyyy"];
cell.dateLabel.text = [formatter2 stringFromDate:datefromstring];
}
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
PFObject *entry = [self.objects objectAtIndex:indexPath.row];
NSString *commentString = entry[#"Request"];
NSString *nameString = #"";
NSLog(#"%#", commentString);
return [Cell heightForCellWithContentString:(NSString *)commentString] +25 ;
}
#pragma mark -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad )
{
if (_webViewController2 == nil) {
self.webViewController2 = [[[WebViewController2 alloc] initWithNibName:#"WebViewController2" bundle:[NSBundle mainBundle]] autorelease];
}
RSSEntry *entry = [_allEntries objectAtIndex:indexPath.row];
_webViewController2.entry = entry;
[self.navigationController pushViewController:_webViewController2 animated:YES];
[self.objects objectAtIndex:indexPath.row];
}
else {
PFObject *entry = [self.objects objectAtIndex:indexPath.row];
if (_webViewController == nil) {
self.webViewController = [[[WebViewController alloc] initWithNibName:#"WebViewController" bundle:[NSBundle mainBundle]] autorelease];
}
_webViewController.finalObject = entry;
[self.navigationController pushViewController:_webViewController animated:YES];
}
#endif
}
As I understand, that should load up 20 items at a time, and when you scroll to the end of those, load up the next 20. However, once I have 20 items, the app crashes, and I get this message:
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 20 beyond bounds [0 .. 19]'
After putting an exception breakpoint in, the line causing the error is in the heightForRow method
PFObject *entry = [self.objects objectAtIndex:indexPath.row];
What's going on?

Related

iOS - Why my next view callback my previous view?

My situation is the next :
I have two view controller.
The first contains an UITableView. When I tap on a cell, the second view is called and display another UITableView.
Problem :
Immediately that my second view has been displayed, it's removed and my app come back on the first view.
In debug mode, I can see that viewDidLoad() is called and the TableView has been initialised because the TableView is filled.
But I don't know why, viewWillDisappear() is called immediately, as if the view was removed...
Could someone to help me out please?
EDIT :
My first View :
#import "CIMSaddlesResearchesSavedViewController.h"
#import <Foundation/Foundation.h>
#interface CIMSaddlesResearchesSavedViewController ()
#property (weak, nonatomic) IBOutlet UITableView *tableView;
#end
#implementation CIMSaddlesResearchesSavedViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
}
- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"NavigationBarBackground"] forBarMetrics:UIBarMetricsDefault];
}
- (void) viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
}
- (UIStatusBarStyle) preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.researches count];
}
- (UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
static NSString *reuseIdentifier = #"researchCell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
CIMSaddleResearch *research;
research = self.researches[indexPath.row];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:#"researchCell"];
}
cell.textLabel.textColor = [UIColor whiteColor];
cell.detailTextLabel.textColor = [UIColor whiteColor];
cell.backgroundColor = [UIColor clearColor];
if (research.dbId && ![research.dbId isEqual:#""]) {
CIMDbManager *dbMngr = [[CIMDbManager alloc] init];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:#"dd/MM/yyyy"];
NSMutableString *minPrice = [NSMutableString stringWithString:#""];
NSMutableString *maxPrice = [NSMutableString stringWithString:#""];
NSMutableString *currencyS = [NSMutableString stringWithString:#""];
CIMCurrency *currency = [[CIMCurrency alloc] init];;
NSMutableString *researchText = [NSMutableString stringWithString:#""];
if (research.customer && ![research.customer isEqual:#""]) {
CIMCustomer *customer = [[CIMCustomer alloc] init];
customer.dbId = research.customer;
customer = [dbMngr firstObjectFromDb:customer];
[researchText appendFormat:#"%# le %#", customer.lastName, [formatter stringFromDate:research.date]];
}
CIMSaddleResearchLine *researchLine = [[CIMSaddleResearchLine alloc] init];
researchLine.saddleResearch = research.dbId;
NSArray *lines = [dbMngr objectsFromDb:researchLine];
for(CIMSaddleResearchLine *line in lines){
if([line.field isEqualToString:#"PRIX_MIN"])
[minPrice appendFormat:#"%#", line.value];
else if([line.field isEqualToString:#"PRIX_MAX"])
[maxPrice appendFormat:#"%#", line.value];
else if([line.field isEqualToString:#"DEVISE"])
[currencyS appendFormat:#"%#", line.value];
}
if(![minPrice isEqual:#""] || ![maxPrice isEqual:#""]){
if(currencyS){
currency.dbId = currencyS;
currency = [dbMngr firstObjectFromDb:currency];
} else {
currency = [dbMngr defaultSocietyCurrency];
}
[researchText appendString:#" | Budget : "];
if(![minPrice isEqual:#""] && ![maxPrice isEqual:#""])
[researchText appendFormat:#"%#%# → %#%#", minPrice, currency.symbol, maxPrice, currency.symbol];
else if(![minPrice isEqual:#""] && [maxPrice isEqual:#""])
[researchText appendFormat:#"%#%# min.", minPrice, currency.symbol];
else if([minPrice isEqual:#""] && ![maxPrice isEqual:#""])
[researchText appendFormat:#"%#%# max.", maxPrice, currency.symbol];
}
NSMutableString *researchDetailText = [NSMutableString stringWithFormat:#"Relance le : %#", [formatter stringFromDate:research.deadline]];
CIMResearchStatus *status = [[CIMResearchStatus alloc] init];
status.dbId = research.status;
status = [dbMngr firstObjectFromDb:status];
if(status){
[researchDetailText appendFormat:#" (%#)", status.name];
}
cell.textLabel.text = researchText;
cell.detailTextLabel.text = researchDetailText;
if (research.comment && ![research.comment isEqual:#""] ) {
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
}
} else {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"saddleCell"];
cell.backgroundColor = [UIColor clearColor];
cell.textLabel.text = NSLocalizedString(#"The saddle is not in this list", nil);
cell.textLabel.textAlignment = NSTextAlignmentCenter;
}
return cell;
}
-(void) tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
CIMSaddleResearch *research = self.researches[indexPath.row];
if (research.comment && ![research.comment isEqual:#""] ) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:NSLocalizedString(#"Comment", nil)
message:research.comment
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *actionOk = [UIAlertAction actionWithTitle:NSLocalizedString(#"Ok", nil)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action){}];
[alert addAction:actionOk];
[self presentViewController:alert animated:YES completion:nil];
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self.navigationController popViewControllerAnimated:YES];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
#pragma mark - Navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"openResultResearch"]) {
UITableView *table = (UITableView*)[(UITableViewCell*)sender superview];
NSIndexPath *index = [table indexPathForCell:(UITableViewCell*) sender];
CIMSaddleResearch *research = self.researches[index.row];
CIMDbManager *dbMngr = [[CIMDbManager alloc] init];
CIMSaddleResearchLine *researchLine = [[CIMSaddleResearchLine alloc] init];
CIMSaddleResearchFormViewController *form = [[CIMSaddleResearchFormViewController alloc] init];
form.minimumPriceRow = [[XLFormRowDescriptor alloc] init];
form.maximumPriceRow = [[XLFormRowDescriptor alloc] init];
form.minimumYearRow = [[XLFormRowDescriptor alloc] init];
form.maximumYearRow = [[XLFormRowDescriptor alloc] init];
form.currency = [[CIMCurrency alloc] init];
NSMutableDictionary *filters = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
[[NSMutableArray alloc] init], #"brand",
[[NSMutableArray alloc] init], #"model",
[[NSMutableArray alloc] init], #"size",
[[NSMutableArray alloc] init], #"color",
[[NSMutableArray alloc] init], #"finishing",
nil];
researchLine.saddleResearch = research.dbId;
NSArray *lines = [dbMngr objectsFromDb:researchLine];
NSSortDescriptor *sortFieldDesc = [[NSSortDescriptor alloc] initWithKey:#"field" ascending:YES selector:#selector(compare:)];
NSSortDescriptor *sortOrderDesc = [[NSSortDescriptor alloc] initWithKey:#"order" ascending:YES selector:#selector(compare:)];
lines = [lines sortedArrayUsingDescriptors:#[sortFieldDesc, sortOrderDesc]];
for(CIMSaddleResearchLine *line in lines){
if([line.field isEqualToString:#"PRIX_MIN"]){
form.minimumPriceRow.value = line.value;
}else if([line.field isEqualToString:#"PRIX_MAX"]){
form.maximumPriceRow.value = line.value;
}else if([line.field isEqualToString:#"ANNEE_MIN"]){
form.minimumYearRow.value = line.value;
}else if([line.field isEqualToString:#"ANNEE_MAX"]){
form.maximumYearRow.value = line.value;
}else if([line.field isEqualToString:#"DEVISE"]){
form.currency.dbId = line.value;
form.currency = [dbMngr firstObjectFromDb:form.currency];
}
else if([line.field isEqualToString:#"GA_REFCONSTRUC"]){
form.serialNumberRow.value = line.value;
}else if([line.field isEqualToString:#"GA_QUARTIER"]){
form.flapRow.value = line.value;
}else if([line.field isEqualToString:#"GA_MARQUE"]){
CIMBrand *brand = [[CIMBrand alloc] init];
brand.dbId = line.value;
[[filters objectForKey:#"brand"] addObject:[dbMngr firstObjectFromDb:brand]];
}else if([line.field isEqualToString:#"GA_MODEL"]){
CIMModel *model = [[CIMModel alloc] init];
model.dbId = line.value;
[[filters objectForKey:#"model"] addObject:[dbMngr firstObjectFromDb:model]];
}else if([line.field isEqualToString:#"GA_TAILLE"]){
CIMSize *size = [[CIMSize alloc] init];
size.dbId = line.value;
[[filters objectForKey:#"size"] addObject:[dbMngr firstObjectFromDb:size]];
}else if([line.field isEqualToString:#"GA_COULEUR"]){
CIMColor *color = [[CIMColor alloc] init];
color.dbId = line.value;
[[filters objectForKey:#"color"] addObject:[dbMngr firstObjectFromDb:color]];
}else if([line.field isEqualToString:#"GA_FINITION"]){
CIMFinishing *finishing = [[CIMFinishing alloc] init];
finishing.dbId = line.value;
[[filters objectForKey:#"finishing"] addObject:[dbMngr firstObjectFromDb:finishing]];
}
}
if(!form.currency.dbId && [form.currency.dbId isEqualToString:#""]){
CIMCustomer *customer = [[CIMCustomer alloc] init];
customer.dbId = research.customer;
customer = [dbMngr firstObjectFromDb:customer];
form.currency.dbId = customer.currency;
form.currency = [dbMngr firstObjectFromDb:form.currency];
}
CIMSaddlesViewController *saddlesViewController = segue.destinationViewController;
saddlesViewController.filters = filters;
saddlesViewController.saddleDbId = [NSMutableString stringWithString:#""];
saddlesViewController.selectionMode = NO;
saddlesViewController.saddleNotFoundOption = NO;
saddlesViewController.showSaddlePictures = YES;
saddlesViewController.showSaddleWarehouse = YES;
saddlesViewController.showToolbar = NO;
saddlesViewController.saddles = [dbMngr stockSaddlesWithFilters:filters
andSerialNumber:form.serialNumberRow.value
andFlap:form.flapRow.value
betweenMinimumPrice:form.minimumPriceRow.value
andMaximumPrice:form.maximumPriceRow.value
inCurrency:form.currency.dbId
betweenMinimumYear:form.minimumYearRow.value
andMaximumYear:form.maximumYearRow.value
inStock:YES];
saddlesViewController.formResearch = form;
saddlesViewController.saddlesPricesCurrency = form.currency;
}
}
#end
My second view :
#import "CIMSaddlesViewController.h"
#interface CIMSaddlesViewController ()
#property (weak, nonatomic) IBOutlet UITableView *tableView;
#end
#implementation CIMSaddlesViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
}
- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"NavigationBarBackground"] forBarMetrics:UIBarMetricsDefault];
}
- (void) viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
}
- (UIStatusBarStyle) preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.saddles count];
}
- (UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
static NSString *reuseIdentifier = #"saddleCell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
CIMItem *saddle;
saddle = self.saddles[indexPath.row];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:#"saddleCell"];
}
cell.textLabel.textColor = [UIColor whiteColor];
cell.detailTextLabel.textColor = [UIColor whiteColor];
cell.backgroundColor = [UIColor clearColor];
if (saddle.dbId && ![saddle.dbId isEqual:#""]) {
NSMutableString *saddleText = [NSMutableString stringWithString:saddle.dbId];
NSMutableString *saddleDetailText = [NSMutableString stringWithString:saddle.name];
// Serial number
if (saddle.serialNumber && ![saddle.serialNumber isEqual:#""]) {
[saddleText appendFormat:#" - %#", saddle.serialNumber];
}
// Warehouse
if (self.showSaddleWarehouse) {
CIMDbManager *dbMngr = [[CIMDbManager alloc] init];
CIMStock *stock = [[CIMStock alloc] init];
stock.item = saddle.dbId;
stock.quantity = [NSNumber numberWithInt:1];
stock = [dbMngr firstObjectFromDb:stock];
if (stock) {
CIMWarehouse *warehouse = [[CIMWarehouse alloc] init];
warehouse.dbId = stock.warehouse;
warehouse = [dbMngr firstObjectFromDb:warehouse];
[saddleText appendFormat:#" → [%#]", warehouse.name];
}
}
// Estimed price
if (self.saddlesPricesCurrency) {
CIMDbManager *dbMngr = [[CIMDbManager alloc] init];
CIMSaddlePrices *saddlePrices = [[CIMSaddlePrices alloc] init];
saddlePrices.item = saddle.dbId;
saddlePrices.currency = self.saddlesPricesCurrency.dbId;
saddlePrices = [dbMngr firstObjectFromDb:saddlePrices];
if (saddlePrices) {
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setMaximumFractionDigits:0];
[numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[numberFormatter setCurrencyCode:self.saddlesPricesCurrency.isoCode];
NSString *isEstimateStr;
if ([saddlePrices.isEstimate isEqual:#"-"]) {
isEstimateStr = NSLocalizedString(#"Official price", nil);
} else {
isEstimateStr = NSLocalizedString(#"Estimation", nil);
}
[saddleText appendFormat:#" | %# (%#)", [numberFormatter stringFromNumber:saddlePrices.price], isEstimateStr];
}
}
cell.textLabel.text = saddleText;
cell.detailTextLabel.text = saddleDetailText;
// Saddle pictures
if (self.showSaddlePictures && [[self.saddlesPicturesDictionary allKeys] containsObject:saddle.dbId]) {
UIButton *accessoryButton = [[UIButton alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 40.0f, 40.0f)];
if ([self.saddlesiPadPictures containsObject:saddle.dbId]) {
[accessoryButton setImage:[UIImage imageNamed:#"SaddleiPadPictureButton"] forState:UIControlStateNormal];
} else {
[accessoryButton setImage:[UIImage imageNamed:#"SaddlePictureButton"] forState:UIControlStateNormal];
}
accessoryButton.tag = indexPath.row;
[accessoryButton addTarget:self action:#selector(showSaddlePicturesViewForSaddleWithSender:) forControlEvents:UIControlEventTouchDown];
cell.accessoryView = accessoryButton;
} else {
cell.accessoryView = nil;
}
} else {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"saddleCell"];
cell.backgroundColor = [UIColor whiteColor];
cell.textLabel.text = NSLocalizedString(#"The saddle is not in this list", nil);
cell.textLabel.textAlignment = NSTextAlignmentCenter;
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.selectionMode) {
CIMItem *saddle = self.saddles[indexPath.row];
[self.saddleDbId setString:saddle.dbId];
[self.navigationController popViewControllerAnimated:YES];
} else {
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
}
#end
To be honest, this project is very big, I begun to work on it since 2 month ago and I'm alone to work on it. I didn't work in Objective-C before and even less with X-Code. I'm discovering features and Objective-C gradually...
In your first VC you call [self.navigationController popViewControllerAnimated:YES]; which tells the navigationVC to pop the currently visible view controller. If you set breakpoints to the tableview didSelectRowAtIndexPath: in first VC and to viewDidLoad in your second VC you'll see in what order they are called. I have a feeling that the order of execution could be the following:
prepare for segue in firstVC
view did load in secondVC
didSelectRowAtIndexPath in first VC
finally your second VC unloads
This is my idea without testing it. Please make sure you really need to pop the VC in didSelectRow

my scrolling through UITableView is somewhat choppy, how can i make it smooth?

Scrolling through the table is somewhat a bit choppy and stutters when scrolling.
Is there any improvements i can make to make it smooth?
here's my cellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {
UITableViewCell *cellEmpty;
if ([tableView isEqual:self.categoryTableView]) {
NSString *CellIdentifierCategory = #"categoryCell";
UITableViewCell *categoryCell = [self.categoryTableView dequeueReusableCellWithIdentifier:CellIdentifierCategory];
if (categoryCell == nil) {
categoryCell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifierCategory];
}
else{
categoryCell.textLabel.text = [_categoryTableArray objectAtIndex:indexPath.row];
return categoryCell;
}
}
if ([tableView isEqual:self.tableView]) {
if (indexPath.section == self.objects.count) {
UITableViewCell *cell = [self tableView:tableView cellForNextPageAtIndexPath:indexPath];
UILabel *loadLabel = (UILabel *)[cell viewWithTag:1];
if (!self.isLoading) {
loadLabel.text = #"The End of Space";
self.tableView.tableFooterView = nil;
}
cell.userInteractionEnabled = NO;
return cell;
}
NSString *CellIdentifier = #"PhotoCell";
InterestsCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[InterestsCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
else{
PFUser *user = [object objectForKey:#"userTookPhoto"];
dispatch_async(dispatch_get_main_queue(), ^{
cell.companyLogo.layer.cornerRadius = cell.companyLogo.frame.size.width / 2;
cell.companyLogo.clipsToBounds = YES;
});
[cell.productImageView setUserInteractionEnabled:YES];
[cell.priceLabel setUserInteractionEnabled:YES];
UITapGestureRecognizer *tapForImage = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleProductImageTap:)];
tapForImage.cancelsTouchesInView = YES;
tapForImage.numberOfTapsRequired = 1;
[cell.productImageView addGestureRecognizer:tapForImage];
UITapGestureRecognizer *tapForPrice = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleProductImageTap:)];
tapForPrice.cancelsTouchesInView = YES;
tapForPrice.numberOfTapsRequired = 1;
[cell.priceLabel addGestureRecognizer:tapForPrice];
cell.productImageView.tag = indexPath.section;
cell.productImageView.file = (PFFile *)object[#"image"];
[cell.productImageView loadInBackground:^(UIImage * _Nullable image, NSError * _Nullable error) {
} progressBlock:^(int percentDone) {
NSLog(#"float value: %f",percentDone * 0.01);
dispatch_async(dispatch_get_main_queue(), ^{
[cell.progressView setProgress:percentDone * 0.01 animated:YES];
});
if (percentDone == 100) {
[cell.progressView setHidden:YES];
}
}];
dispatch_async(dispatch_get_main_queue(), ^{
cell.productTitle.text = object[#"titleOfPhoto"];
});
[cell.companyLogo setUserInteractionEnabled:YES];
UITapGestureRecognizer *tapGesture1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(segueCompanyProfile)];
tapGesture1.numberOfTapsRequired = 1;
[cell.companyLogo addGestureRecognizer:tapGesture1];
if (user[#"profileImage"]) {
cell.companyLogo.file = (PFFile *)user[#"profileImage"];
[cell.companyLogo loadInBackground];
}
else{
dispatch_async(dispatch_get_main_queue(), ^{
UIImage *image = [UIImage imageNamed:#"defaultBrandLogo.png"];
cell.companyLogo.image = image;
});
}
dispatch_async(dispatch_get_main_queue(), ^{
[cell.companyLabelButton setTitle:user.username forState:UIControlStateNormal];
cell.companyLabelButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
cell.companyLabelButton.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
});
[cell.companyLabelButton addTarget:self action:#selector(segueCompanyProfile) forControlEvents:UIControlEventTouchUpInside];
NSNumber *price = object[#"PriceOfPhoto"];
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setNumberStyle: NSNumberFormatterCurrencyStyle];
NSString *numberAsString = [numberFormatter stringFromNumber:price];
NSString *priceLabelText = [NSString stringWithFormat:#"%#",numberAsString];
dispatch_async(dispatch_get_main_queue(), ^{
cell.priceLabel.text = priceLabelText;
});
// UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, cell.productTitle.frame.origin.y + cell.productTitle.frame.size.height + 10, self.view.frame.size.width - 30, 2)];
// line.backgroundColor = [UIColor groupTableViewBackgroundColor];
// [cell.cardView addSubview:line];
cell.likeButtonOutlet.delegate = self;
cell.likeButtonOutlet.sectionIndex = indexPath.section;
NSArray *likesArray = object[#"likesBy"];
if (likesArray.count > 0) {
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
NSString *groupingSeparator = [[NSLocale currentLocale] objectForKey:NSLocaleGroupingSeparator];
[formatter setGroupingSeparator:groupingSeparator];
[formatter setGroupingSize:3];
[formatter setAlwaysShowsDecimalSeparator:NO];
[formatter setUsesGroupingSeparator:YES];
NSString *formattedString = [formatter stringFromNumber:[NSNumber numberWithFloat:likesArray.count]];
dispatch_async(dispatch_get_main_queue(), ^{
cell.likeCountLabel.text = formattedString;
});
}
else{
dispatch_async(dispatch_get_main_queue(), ^{
cell.likeCountLabel.text = nil;
});
}
if (likesArray.count > 0) {
for (NSString *likes in likesArray) {
if ([likes isEqualToString:[PFUser currentUser].objectId]) {
dispatch_async(dispatch_get_main_queue(), ^{
[cell.likeButtonOutlet setSelected:YES];
});
}
else{
dispatch_async(dispatch_get_main_queue(), ^{
[cell.likeButtonOutlet setSelected:NO];
});
}
}
}
else{
dispatch_async(dispatch_get_main_queue(), ^{
[cell.likeButtonOutlet setSelected:NO];
});
}
}
return cell;
}
return cellEmpty;
}

Parse Pagination loadNextPage 2nd Page Loads Twice

In my Parse app, I have Pagination enabled, and for testing purposes, objects per page set to 5. When I run the app I get this in my TableView
1
2
3
4
5
Load More
After clicking Load More the entire table looks like:
1
2
3
4
5
6
7
8
9
10
6
7
8
9
10
Clicking Load More after this will add the set of 11-15 twice. What is going on?
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
// The className to query on
self.parseClassName = #"Prayers";
// Whether the built-in pull-to-refresh is enabled
self.pullToRefreshEnabled = YES;
// Whether the built-in pagination is enabled
self.paginationEnabled = YES;
// The number of objects to show per page
self.objectsPerPage = 5;
}
return self;
}
- (PFQuery *)queryForTable {
PFQuery *query = [PFQuery queryWithClassName:#"Prayers"];
// If no objects are loaded in memory, we look to the cache first to fill the table
// and then subsequently do a query against the network.
if (self.objects.count == 0) {
query.cachePolicy = kPFCachePolicyCacheThenNetwork;
}
[query orderByDescending:#"createdAt"];
return query;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
object:(PFObject *)object
{
static NSString *CellIdentifier = #"Cell";
Cell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[Cell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
self.theObject = object;
BOOL anony = [object[#"Anonymous"] boolValue];
cell.profileName.text = object[#"Title"];
cell.contentLabel.text = object[#"Request"];
cell.firstName = object[#"FirstName"];
cell.lastName = object[#"LastName"];
cell.iostoken = object[#"DeviceID"];
cell.request = object[#"Title"];
cell.prayerObject = object;
PFFile *thumbnail = object[#"ProfilePic"];
cell.profilePic.image = [UIImage imageNamed:#"AppIcon60x60#2x.png"];
/*[cell.commentButton addTarget:self action:#selector(didTapCommentButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[cell.commentButton setTitle:#"Share" forState:UIControlStateNormal];
[cell.commentButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[cell.commentButton setTitleColor:[UIColor greenColor] forState:UIControlStateHighlighted];*/
[thumbnail getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
UIImage *thumbnailImage = [UIImage imageWithData:imageData];
UIImageView *thumbnailImageView = [[UIImageView alloc] initWithImage:thumbnailImage];
cell.profilePic.image = thumbnailImage;
}];
NSString *dates = object[#"dateMade"];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:#"MMM_dd_yyyy"];
NSDate *datefromstring = [formatter dateFromString:dates];
NSDateFormatter *formatter2 = [[NSDateFormatter alloc] init];
[formatter2 setDateFormat:#"MMM dd, yyyy"];
cell.dateLabel.text = [formatter2 stringFromDate:datefromstring];
UIFont *cellFont = [UIFont fontWithName:#"Verdana-Bold" size:15];
UIFont *cellFont2 = [UIFont fontWithName:#"Verdana-Bold" size:12];
return cell;
}
- (PFObject *)objectAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == self.objects.count) {
return nil;
} else {
return [super objectAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]];
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
PFObject *object = [self objectAtIndexPath:indexPath];
if (object == nil) {
// Return a fixed height for the extra ("Load more") row
return 70;
} else {
NSLog(#"%lu", (unsigned long)[self.objects count]);
PFObject *entry = [self.objects objectAtIndex:indexPath.row];
NSString *commentString = entry[#"Request"];
NSString *nameString = #"";
NSLog(#"%#", commentString);
return [Cell heightForCellWithContentString:(NSString *)commentString] +25 ;
}
}
#pragma mark -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[super tableView:tableView didSelectRowAtIndexPath:indexPath];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (indexPath.row == self.objects.count && self.paginationEnabled) {
// Load More Cell
NSLog(#"Load More");
[self loadNextPage];
}
-(PFQuery *)queryForTable {
...
...
...
//Always trigger a network request.
[tableQuery setCachePolicy:kPFCachePolicyNetworkOnly];
//If no objects are loaded in memory, we look to the cache first to fill the table and then subsequently do a query against the network.
if(self.objects.count == 0) {
[tableQuery setCachePolicy: kPFCachePolicyCacheThenNetwork];
}
...
...
...
return tableQuery;
}

PFQueryTableViewController has line going through cells when pushed

I have a PFQueryTableViewController in my app. If it is a root view of a controller, it is fine. However, if I push it onto another view, there is a strange line that goes through the top of each cell.
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
// The className to query on
self.parseClassName = #"Prayers";
// Whether the built-in pull-to-refresh is enabled
self.pullToRefreshEnabled = YES;
// Whether the built-in pagination is enabled
self.paginationEnabled = YES;
// The number of objects to show per page
self.objectsPerPage = 20;
}
return self;
}
- (PFQuery *)queryForTable {
PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
// If no objects are loaded in memory, we look to the cache first to fill the table
// and then subsequently do a query against the network.
if (self.objects.count == 0) {
query.cachePolicy = kPFCachePolicyCacheThenNetwork;
}
[query orderByDescending:#"createdAt"];
return query;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
object:(PFObject *)object
{
static NSString *CellIdentifier = #"Cell";
Cell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[Cell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
self.theObject = object;
// Configure the cell to show todo item with a priority at the bottom
cell.profileName.text = object[#"Title"];
cell.contentLabel.text = object[#"Request"];
cell.firstName = object[#"FirstName"];
cell.lastName = object[#"LastName"];
cell.iostoken = object[#"DeviceID"];
cell.request = object[#"Title"];
cell.prayerObject = object;
PFFile *thumbnail = object[#"ProfilePic"];
cell.profilePic.image = [UIImage imageNamed:#"AppIcon60x60#2x.png"];
[cell.commentButton addTarget:self action:#selector(didTapCommentButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[cell.commentButton setTitle:#"Share" forState:UIControlStateNormal];
[cell.commentButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[cell.commentButton setTitleColor:[UIColor greenColor] forState:UIControlStateHighlighted];
[thumbnail getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
UIImage *thumbnailImage = [UIImage imageWithData:imageData];
UIImageView *thumbnailImageView = [[UIImageView alloc] initWithImage:thumbnailImage];
cell.profilePic.image = thumbnailImage;
}];
NSString *dates = object[#"dateMade"];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:#"MMM_dd_yyyy"];
NSDate *datefromstring = [formatter dateFromString:dates];
NSDateFormatter *formatter2 = [[NSDateFormatter alloc] init];
[formatter2 setDateFormat:#"MMM dd, yyyy"];
cell.dateLabel.text = [formatter2 stringFromDate:datefromstring];
UIFont *cellFont = [UIFont fontWithName:#"Verdana-Bold" size:15];
UIFont *cellFont2 = [UIFont fontWithName:#"Verdana-Bold" size:12];
return cell;
}
Just having this as root view presents this:
If I present it from another view like this:
-(void)myPrayers {
BlogView1 *prayers = [[BlogView1 alloc] init];
[self.navigationController pushViewController:prayers animated:YES];
}
It looks like this:
That looks like a UITableViewCellSeperatorStyle Property needing to be set to UITableViewCellSeparatorStyleNone...
[_table setSeparatorStyle:UITableViewCellSeparatorStyleNone];
OR
set the separator color of your UITableViewCell to clear color
[_table setSeparatorColor:<#(UIColor *)#>]

TableView Not Showing All Rows For Blog

I have a number of blog apps. Recently, some of them started experiencing some issues. I use ASIHTTP Classes and GDataXML Classes to parse the xml of a wordpress feed, and put each item (article) into a mutable array. The tableview is then supposed to load all of the stories into a cell for each article. The issue I am having is that new articles are not being displayed on first run, the user is having to Pull to Refresh, and then the new article displays. I ran a test just now on an app. The article was posted a few hours ago. I ran the app, it wasn't there. Pulled to refresh, it showed. Closed down the app completely, restarted it, and it was gone again. Here is the code in the TableView's implementation:
#implementation RootViewController
- (void)refresh {
self.allEntries = [NSMutableArray array];
self.queue = [[[NSOperationQueue alloc] init] autorelease];
self.feeds = [NSArray arrayWithObjects:#"http://bubblycandacebabbles.wordpress.com/?cat=-2008&feed=rss2",
nil];
for (NSString *feed in _feeds) {
NSURL *url = [NSURL URLWithString:feed];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[_queue addOperation:request];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
[activity startAnimating];
//[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"navbarcopy.png"] forBarMetrics:UIBarMetricsDefault];
self.title = #"Blog";
CGFloat nRed=111.0/255.0;
CGFloat nBlue=209/255.0;
CGFloat nGreen=229.0/255.0;
UIColor *myColor=[[UIColor alloc]initWithRed:nRed green:nBlue blue:nGreen alpha:1];
UIBarButtonItem *font = [[UIBarButtonItem alloc] initWithTitle:#"Change Font Size" style:UIBarButtonItemStylePlain target:self action:#selector(fontsizes)];
self.navigationController.navigationItem.rightBarButtonItem = font;
self.tableView.backgroundColor = myColor;
self.refreshControl = [[UIRefreshControl alloc] init];
[self.refreshControl addTarget:self action:#selector(refreshInvoked:forState:) forControlEvents:UIControlEventValueChanged];
[self refresh];
}
-(void) refreshInvoked:(id)sender forState:(UIControlState)state {
// Refresh table here...
[_allEntries removeAllObjects];
[self.tableView reloadData];
[self refresh];
}
- (void)parseRss:(GDataXMLElement *)rootElement entries:(NSMutableArray *)entries {
NSArray *channels = [rootElement elementsForName:#"channel"];
for (GDataXMLElement *channel in channels) {
NSString *blogTitle = [channel valueForChild:#"title"];
NSArray *items = [channel elementsForName:#"item"];
for (GDataXMLElement *item in items) {
NSString *articleTitle = [item valueForChild:#"title"];
NSString *articleUrl = [item valueForChild:#"link"];
NSString *articleDateString = [item valueForChild:#"pubDate"];
NSDate *articleDate = [NSDate dateFromInternetDateTimeString:articleDateString formatHint:DateFormatHintRFC822];
NSString *articleImage = [item valueForChild:#"content:encoded"];
NSScanner *theScanner;
NSString *gt =nil;
theScanner = [NSScanner scannerWithString:articleImage];
NSString *comments = [articleUrl stringByAppendingString:#"#respond"];
NSString *commentslink = [NSString stringWithFormat: #"Leave A Comment",comments];
// find start of tag
[theScanner scanUpToString:#"alt=\"\" width=" intoString:NULL] ;
// find end of tag
[theScanner scanUpToString:#"/>" intoString:&gt] ;
// replace the found tag with a space
//(you can filter multi-spaces out later if you wish)
NSString *test = [articleImage stringByReplacingOccurrencesOfString:[ NSString stringWithFormat:#"%#", gt] withString:#"alt=\"\" width=\"150\" height=\"150\""];
NSString *final = [test stringByReplacingOccurrencesOfString:#"float:none;height:30px" withString:#"float:none;height:1px"];
NSDateFormatter * dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
[dateFormatter setDateStyle:NSDateFormatterShortStyle];
NSString *dateofarticle = [dateFormatter stringFromDate:articleDate];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *smalltitle = [defaults objectForKey:#"Title"];
NSString *smallbody = [defaults objectForKey:#"Article"];
NSString *bodyoftext = [[[[[[[[[[[#"<head><body bgcolor=\"#6fd1e5\" text=\"#CC0099\"><style type='text/css'>a > img {pointer-events: none;cursor: default;max-width: 310;}</style></head><b><font size=" stringByAppendingString: smalltitle ] stringByAppendingString:#"><div align=\"left\"><FONT FACE=\"noteworthy\">" ]stringByAppendingString:articleTitle] stringByAppendingString:#"</font></b><font size=" ] stringByAppendingString:smallbody ] stringByAppendingString:#"><div align=\"left\"><FONT FACE=\"noteworthy\">"] stringByAppendingString:dateofarticle] stringByAppendingString:#"</div></p><FONT FACE=\"noteworthy\">"] stringByAppendingString:final] stringByAppendingString:commentslink]stringByAppendingString:#"</FONT>"];
RSSEntry *entry = [[[RSSEntry alloc] initWithBlogTitle:blogTitle
articleTitle:articleTitle
articleUrl:articleUrl
articleDate:articleDate
articleImage:bodyoftext] autorelease];
[entries addObject:entry];
}
}
}
- (void)parseFeed:(GDataXMLElement *)rootElement entries:(NSMutableArray *)entries {
if ([rootElement.name compare:#"rss"] == NSOrderedSame) {
[self parseRss:rootElement entries:entries];
} else if ([rootElement.name compare:#"feed"] == NSOrderedSame) {
[self parseAtom:rootElement entries:entries];
} else {
NSLog(#"Unsupported root element: %#", rootElement.name);
}
}
// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [_allEntries count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
Cell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[Cell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
RSSEntry *entry = [_allEntries objectAtIndex:indexPath.row];
NSString *substring = #"http://bubblycandacebabbles.files.wordpress.com";
NSRange textRange = [entry.articleImage rangeOfString:substring];
if(textRange.location != NSNotFound){
NSString *thearticleImage = entry.articleImage;
NSRegularExpression *expression = [NSRegularExpression regularExpressionWithPattern:#"src=\"([^\"]+)\"" options:NSRegularExpressionCaseInsensitive error:NULL];
NSString *someString = thearticleImage;
NSString *oneurl = [someString substringWithRange:[expression rangeOfFirstMatchInString:someString options:NSMatchingCompleted range:NSMakeRange(0, [someString length])]];
NSString *finalstring = [oneurl stringByReplacingOccurrencesOfString:#"src=\"" withString:#""];
NSString *thefinalstring = [finalstring stringByReplacingOccurrencesOfString:#"\"" withString:#""];
NSDateFormatter * dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setTimeZone:[NSTimeZone localTimeZone]];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
[dateFormatter setDateStyle:NSDateFormatterShortStyle];
CGFloat nRed=204.0/255.0;
CGFloat nBlue=0/255.0;
CGFloat nGreen=153.0/255.0;
UIColor *myColortext=[[UIColor alloc]initWithRed:nRed green:nBlue blue:nGreen alpha:1];
NSString *articleDateString = [dateFormatter stringFromDate:entry.articleDate];
UIFont *cellFont = [UIFont fontWithName:#"noteworthy" size:16];
UIFont *cellFont2 = [UIFont fontWithName:#"noteworthy" size:12];
CALayer * l = [cell.imageView layer];
[l setMasksToBounds:YES];
[l setCornerRadius:11];
[l setBorderWidth:2.0];
[l setBorderColor:[[UIColor blackColor] CGColor]];
cell.textLabel.text = entry.articleTitle;
cell.textLabel.numberOfLines = 2;
cell.detailTextLabel.adjustsFontSizeToFitWidth = YES;
cell.detailTextLabel.text = [NSString stringWithFormat:#"%# - Mother May I Blog", articleDateString];
cell.textLabel.font = cellFont;
cell.detailTextLabel.font = cellFont2;
cell.textLabel.textColor = myColortext;
cell.detailTextLabel.textColor = myColortext;
[cell.imageView setImageWithURL:[NSURL URLWithString:thefinalstring] placeholderImage:[UIImage imageNamed:#"iphoneicon#2x.png"]];
}
else {
CALayer * l = [cell.imageView layer];
[l setMasksToBounds:YES];
[l setCornerRadius:11];
[l setBorderWidth:2.0];
[l setBorderColor:[[UIColor blackColor] CGColor]];
NSDateFormatter * dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setTimeZone:[NSTimeZone localTimeZone]];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
[dateFormatter setDateStyle:NSDateFormatterShortStyle];
NSString *articleDateString = [dateFormatter stringFromDate:entry.articleDate];
UIFont *cellFont = [UIFont fontWithName:#"noteworthy" size:16];
UIFont *cellFont2 = [UIFont fontWithName:#"noteworthy" size:12];
cell.imageView.image = [UIImage imageNamed:#"iphoneicon#2x.png"];
cell.textLabel.text = entry.articleTitle;
cell.textLabel.numberOfLines = 2;
cell.detailTextLabel.adjustsFontSizeToFitWidth = YES;
cell.detailTextLabel.text = [NSString stringWithFormat:#"%# - Mother May I Blog", articleDateString];
CGFloat nRed=204.0/255.0;
CGFloat nBlue=0/255.0;
CGFloat nGreen=153.0/255.0;
UIColor *myColortext=[[UIColor alloc]initWithRed:nRed green:nBlue blue:nGreen alpha:1];
cell.textLabel.font = cellFont;
cell.detailTextLabel.font = cellFont2;
cell.textLabel.textColor = myColortext;
cell.detailTextLabel.textColor = myColortext;
}
return cell;
}
You need to invoke
[self.tableView reloadData];
at some point after your data has finished loading. How exactly you do this is a bit tricky, you need some way of telling when your operation queue is empty. Alternatively, you could theoretically call it after each operation in the queue is complete, that way the table will populate one at a time. This could cause problems if the user is on a slow connection, as reloading the table can cause jumps in the user experience, and I'm not positive on the thread safety of calling reloadData from a different thread

Resources