this is my .h file.in this file i declare array for searchresult and mail array that i want to use for filter is arrfullname.
DisplayAppointmentViewController.h
//
// DisplayAppointmentViewController.h
// AffordPlan
//
// Created by apple on 17/08/16.
// Copyright © 2016 Taxsmart. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
#import "CustomClass.h"
#import "AppoinmentTableViewCell.h"
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
#import <CoreTelephony/CTCarrier.h>
#import "AddAppoinmentViewController.h"
#import "CreatePlanViewController.h"
#import "LeadViewController.h"
#import "Sqlite.h"
#import "outComeViewController.h"
#class RadioButton;
#interface DisplayAppointmentViewController : UIViewController<UITableViewDelegate,UITableViewDataSource,UISearchDisplayDelegate,UISearchControllerDelegate,UISearchBarDelegate,UISearchResultsUpdating,MFMailComposeViewControllerDelegate,MFMessageComposeViewControllerDelegate>
{
NSArray *arrsearchresult;
NSMutableArray *arrfullname;
NSMutableArray *arrdatetime;
NSMutableArray *arrappointment_date;
NSMutableArray *appointmenttime;
}
#property (strong, nonatomic) IBOutlet UITableView *tblAppoinment;
#property (strong, nonatomic) IBOutlet RadioButton *btnSearchByName;
#property (strong, nonatomic) IBOutlet RadioButton *btnSearchByDate;
#property (strong, nonatomic) IBOutlet UISearchBar *searchResultBar;
- (IBAction)btnSearchByNamePress:(id)sender;
- (IBAction)btnSearchByDatePress:(id)sender;
#property CustomClass *customClass;
- (IBAction)btnBackPressed:(id)sender;
#end
this is my .m file
DisplayAppointmentViewController.m
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
if (tableView == self.searchDisplayController.searchResultsTableView) {
return [arrsearchresult count];
} else {
return [arrfullname count];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #"SimpleTableCell";
AppoinmentTableViewCell *cell = (AppoinmentTableViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"AppoinmentTableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
if (tableView == self.searchDisplayController.searchResultsTableView)
{
arrfullname = [arrsearchresult objectAtIndex:indexPath.row];
cell.lblFullname.text = [arrsearchresult objectAtIndex:indexPath.row];
cell.lblDate.text = [arrsearchresult objectAtIndex:indexPath.row];
cell.lblTime.text = [arrsearchresult objectAtIndex:indexPath.row];
}
cell.btnCall.tag = indexPath.row;
cell.btnMail.tag = indexPath.row;
cell.btnSms.tag = indexPath.row;
cell.btnCreatePlan.tag = indexPath.row;
cell.btnAppointment.tag = indexPath.row;
cell.btnStatus.tag=indexPath.row;
}
cell.clipsToBounds = YES;
if ([strCheckVC isEqualToString:#"OpenLead"])
{
cell.lblFullname.text = [arrfullname objectAtIndex:indexPath.row];
[self databaseOpen];
NSString *query_user=[ NSString stringWithFormat:#"Select * from lead_status where row_lead_id = %# and lead_followup_datetime != ' ' order by rowid desc limit 1",[arrRowid objectAtIndex:indexPath.row]];
NSArray *rowids = [[NSArray alloc]init];
rowids =[[database executeQuery:query_user]mutableCopy];
NSLog(#"%#",rowids);
[database close];
if (rowids.count > 0 )
{
NSString *dateString = [[rowids valueForKey:#"lead_followup_datetime"]objectAtIndex:0];
NSArray *components = [dateString componentsSeparatedByString:#" "];
NSString *date = components[0];
NSString *time = components[1];
// date convert
NSString *dateStr = [NSString stringWithFormat:#"%#",date];
NSString *timestr = [NSString stringWithFormat:#"%#",time];
// Convert string to date object
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:#"HH:mm:ss"];
NSDate *date11 = [dateFormat dateFromString:timestr];
NSDateFormatter* df = [[NSDateFormatter alloc]init];
[df setDateFormat:#"hh:mm a"];
NSString *depResult = [df stringFromDate:date11];
cell.lblTime.text = depResult;
dateStr = [NSString stringWithFormat:#"%#",date];
// Convert string to date object
dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:#"yyyy-mm-dd"];
NSDate *viewdt = [dateFormat dateFromString:dateStr];
//date11 = [dateFormat dateFromString:dateStr];
NSLog(#"%#",date);
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:#"yyyy-MM-dd"];
NSDate *date22 = [dateFormatter dateFromString:dateStr];
[dateFormatter setDateFormat:#"dd MMM yyyy"];
NSString *dateWithNewFormat = [dateFormatter stringFromDate:date22];
NSLog(#"dateWithNewFormat: %#", dateWithNewFormat);
// df = [[NSDateFormatter alloc]init];
// [df setDateFormat:#"dd MMM yyyy"];
// depResult = [df stringFromDate:viewdt];
//
cell.lblDate.text = dateWithNewFormat;
}
else
{
// date convert
NSString *dateStr = [NSString stringWithFormat:#"%#",[appointmenttime objectAtIndex:indexPath.row]];
// Convert string to date object
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:#"HH:mm:ss"];
NSDate *date = [dateFormat dateFromString:dateStr];
NSLog(#"%#",date);
NSDateFormatter* df = [[NSDateFormatter alloc]init];
[df setDateFormat:#"hh:mm a"];
NSString *depResult = [df stringFromDate:date];
cell.lblTime.text = depResult;
dateStr = [NSString stringWithFormat:#"%#",[arrappointment_date objectAtIndex:indexPath.row]];
// Convert string to date object
dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:#"yyyy-mm-dd"];
date = [dateFormat dateFromString:dateStr];
NSLog(#"%#",date);
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:#"yyyy-MM-dd"];
NSDate *date22 = [dateFormatter dateFromString:dateStr];
[dateFormatter setDateFormat:#"dd MMM yyyy"];
NSString *dateWithNewFormat = [dateFormatter stringFromDate:date22];
NSLog(#"dateWithNewFormat: %#", dateWithNewFormat);
// df = [[NSDateFormatter alloc]init];
// [df setDateFormat:#"dd MMM yyyy"];
// depResult = [df stringFromDate:date];
//
cell.lblDate.text = dateWithNewFormat;
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if ([[arremail objectAtIndex:indexPath.row] isEqual:[NSNull null]] || [[arremail objectAtIndex:indexPath.row] isEqualToString:#"<null>"] || [[arremail objectAtIndex:indexPath.row] isEqualToString:#""] )
{
cell.btnMail.hidden = NO;
}
NSUInteger hours_passed = [[arrhours_passed objectAtIndex:indexPath.row] integerValue];
if (hours_passed <= 72)
{
cell.colorView.backgroundColor = [UIColor whiteColor];
}
else if (hours_passed <= 144)
{
cell.colorView.backgroundColor = [UIColor colorWithRed:219.0/255.0 green:157.0/255.0 blue:157.0/255.0 alpha:1.0];
cell.lblDate.textColor = [UIColor whiteColor];
cell.lblTime.textColor = [UIColor whiteColor];
cell.lblFullname.textColor = [UIColor whiteColor];
}
else if (hours_passed <= 216)
{
cell.colorView.backgroundColor = [UIColor colorWithRed:202.0/255.0 green:114.0/255.0 blue:114.0/255.0 alpha:1.0];
cell.lblDate.textColor = [UIColor whiteColor];
cell.lblTime.textColor = [UIColor whiteColor];
cell.lblFullname.textColor = [UIColor whiteColor];
}
else if (hours_passed <= 288)
{
cell.colorView.backgroundColor = [UIColor colorWithRed:189.0/255.0 green:78.0/255.0 blue:78.0/255.0 alpha:1.0];
cell.lblDate.textColor = [UIColor whiteColor];
cell.lblTime.textColor = [UIColor whiteColor];
cell.lblFullname.textColor = [UIColor whiteColor];
}
[self databaseOpen];
NSString *str = [NSString stringWithFormat:#"Select * from lead_followup where rowid=%#",[arrRowid objectAtIndex:indexPath.row]];
NSMutableArray *arr = [[NSMutableArray alloc]init];
arr = [[database executeQuery:str]mutableCopy];
NSLog(#"arr data %#",arr);
[database close];
NSString *strsms;
if (arr.count != 0)
{
strsms = [NSString stringWithFormat:#"%#",[[arr valueForKey:#"followed_by_sms"]objectAtIndex:0]];
if ([strsms isEqualToString:#"0"])
{
if (hours_passed <= 72)
{
[cell.btnSms setImage:[UIImage imageNamed:#"Chatgray"] forState:UIControlStateNormal];
}
else if (hours_passed > 72)
{
//white
[cell.btnSms setImage:[UIImage imageNamed:#"chatwhite"] forState:UIControlStateNormal];
}
}
/*else
{
// green icon
[cell.btnSms setImage:[UIImage imageNamed:#"Chatgreen"] forState:UIControlStateNormal];
}*/
NSString *strCall = [NSString stringWithFormat:#"%#",[[arr valueForKey:#"followed_by_call"]objectAtIndex:0]];
NSLog(#"%#",strCall);
if ([strCall isEqualToString:#"0"])
{
if (hours_passed <= 72)
{
//blackCallGray
[cell.btnCall setImage:[UIImage imageNamed:#"CallGray"] forState:UIControlStateNormal];
}
else if (hours_passed > 72)
{
[cell.btnCall setImage:[UIImage imageNamed:#"CallWhite"] forState:UIControlStateNormal];
}
}
else
{
[cell.btnCall setImage:[UIImage imageNamed:#"CallGreen"] forState:UIControlStateNormal];
// green icon
}
NSString *strmail = [NSString stringWithFormat:#"%#",[[arr valueForKey:#"followed_by_mail"]objectAtIndex:0]];
NSLog(#"%#",strmail);
if ([strmail isEqualToString:#"0"])
{
if (hours_passed <= 72)
{
[cell.btnMail setImage:[UIImage imageNamed:#"Mailgray"] forState:UIControlStateNormal];
}
else if (hours_passed > 72)
{
[cell.btnMail setImage:[UIImage imageNamed:#"MailWhite"] forState:UIControlStateNormal];
//white
}
}
/*else
{
[cell.btnMail setImage:[UIImage imageNamed:#"MailGreen"] forState:UIControlStateNormal];
// green icon
}*/
}
[cell.btnCall addTarget:self
action:#selector(callDo:) forControlEvents:UIControlEventTouchDown];
[cell.btnSms addTarget:self
action:#selector(smsDo:) forControlEvents:UIControlEventTouchDown];
[cell.btnMail addTarget:self
action:#selector(mailDo:) forControlEvents:UIControlEventTouchDown];
[cell.btnStatus addTarget:self
action:#selector(Status:) forControlEvents:UIControlEventTouchDown];
[cell.btnAppointment addTarget:self
action:#selector(AddappointmentId:) forControlEvents:UIControlEventTouchDown];
[cell.btnCreatePlan addTarget:self
action:#selector(CreatePlan:) forControlEvents:UIControlEventTouchDown];
}
else
{
cell.lblFullname.text = [arrfullname objectAtIndex:indexPath.row];
cell.btnSms.hidden = YES;
cell.btnCall.hidden = YES;
cell.btnMail.hidden = YES;
cell.colorView.hidden =YES;
// cell.lblTime.text = [appointmenttime objectAtIndex:indexPath.row];
//cell.lblDate.text = [arrappointment_date objectAtIndex:indexPath.row];
NSString *dateStr = [NSString stringWithFormat:#"%#",[appointmenttime objectAtIndex:indexPath.row]];
// Convert string to date object
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:#"HH:mm:ss"];
NSDate *date = [dateFormat dateFromString:dateStr];
NSLog(#"%#",date);
NSDateFormatter* df = [[NSDateFormatter alloc]init];
[df setDateFormat:#"hh:mm a"];
NSString *depResult = [df stringFromDate:date];
cell.lblTime.text = depResult;
dateStr = [NSString stringWithFormat:#"%#",[arrappointment_date objectAtIndex:indexPath.row]];
// Convert string to date object
dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:#"yyyy-mm-dd"];
date = [dateFormat dateFromString:dateStr];
NSLog(#"%#",date);
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:#"yyyy-MM-dd"];
NSDate *date22 = [dateFormatter dateFromString:dateStr];
[dateFormatter setDateFormat:#"dd MMM yyyy"];
NSString *dateWithNewFormat = [dateFormatter stringFromDate:date22];
NSLog(#"dateWithNewFormat: %#", dateWithNewFormat);
// df = [[NSDateFormatter alloc]init];
// [df setDateFormat:#"dd MMM yyyy"];
// depResult = [df stringFromDate:date];
//
cell.lblDate.text = dateWithNewFormat;
}
/* UIView *bgColorView = [[UIView alloc] init];
bgColorView.backgroundColor = [UIColor clearColor];
[cell setSelectedBackgroundView:bgColorView];*/
return cell;
}
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:#"name contains[c] %#", searchText];
arrsearchresult = [arrfullname filteredArrayUsingPredicate:resultPredicate];
[self.tblAppoinment reloadData];
}
-(BOOL)searchDisplayController:(UISearchController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
[self filterContentForSearchText:searchString
scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
objectAtIndex:[self.searchDisplayController.searchBar
selectedScopeButtonIndex]]];
return YES;
}
and my errorlog is
2016-12-15 15:07:44.534 Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x7fb59aef6930'
*** First throw call stack:
(
0 CoreFoundation 0x000000010898ae65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000108403deb objc_exception_throw + 48
2 CoreFoundation 0x000000010899348d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00000001088e090a ___forwarding___ + 970
4 CoreFoundation 0x00000001088e04b8 _CF_forwarding_prep_0 + 120
5 xxxxx 0x0000000107d629ee -[DisplayAppointmentViewController tableView:cellForRowAtIndexPath:] + 10894
6 UIKit 0x0000000109910e43 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 766
7 UIKit 0x0000000109910f7b -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74
8 UIKit 0x00000001098e5a39 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2996
9 UIKit 0x000000010991a01c -[UITableView _performWithCachedTraitCollection:] + 92
10 UIKit 0x0000000109900edc -[UITableView layoutSubviews] + 224
11 UIKit 0x000000010986e4a3 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 703
12 QuartzCore 0x00000001095fa59a -[CALayer layoutSublayers] + 146
13 QuartzCore 0x00000001095eee70 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
14 QuartzCore 0x00000001095eecee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
15 QuartzCore 0x00000001095e3475 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
16 QuartzCore 0x0000000109610c0a _ZN2CA11Transaction6commitEv + 486
17 UIKit 0x00000001097b1f7c _UIApplicationHandleEventQueue + 7329
18 CoreFoundation 0x00000001088b6a31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
19 CoreFoundation 0x00000001088ac95c __CFRunLoopDoSources0 + 556
20 CoreFoundation 0x00000001088abe13 __CFRunLoopRun + 867
21 CoreFoundation 0x00000001088ab828 CFRunLoopRunSpecific + 488
22 GraphicsServices 0x000000010ed40ad2 GSEventRunModal + 161
23 UIKit 0x00000001097b7610 UIApplicationMain + 171
24 xxxxx 0x0000000107d50bbf main + 111
25 libdyld.dylib 0x000000010adfa92d start + 1
26 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Foundation 0x000000010e034888 -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] + 226
Foundation 0x000000010df8a997 -[NSObject(NSKeyValueCoding) valueForKey:] + 280
Foundation 0x000000010dfc5319 -[NSFunctionExpression expressionValueWithObject:context:] + 1096
You crash log said there is issue in key value of predicate in method
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
Place break-point, check your code run time and correct your predicate according to data-source.
The table view is not working when loading.It is giving an error.Here is the error.
NSRangeException', reason: '* -[__NSArrayM objectAtIndex:]: index 1
beyond bounds [0 .. 0]'
Here is my code.
- (void)viewDidLoad
{
[super viewDidLoad];
uiButtonArray =[[NSMutableArray alloc]init];
[SharedPreferenceUtil saveBoolValueInUserDefaults:YES forKey:#"viewupdate"];
indexval = 0;
if (isNotification)
{
isNotification = NO;
[UIApplication sharedApplication].applicationIconBadgeNumber=0;
//[[UIApplication sharedApplication]cancelAllLocalNotifications];
}
[self getRemarks];
[self updateUI];
// Do any additional setup after loading the view.
}
-(void) viewDidLayoutSubviews
{
[remarksTable setFrame:CGRectMake(5, 190, [[UIScreen mainScreen]bounds].size.width-20, [[UIScreen mainScreen]bounds].size.height-180)];
[Calendarscroll setFrame:CGRectMake(0,90,320, 59)];
[Calendarscroll setBackgroundColor:[UIColor whiteColor]];
Calendarscroll.contentSize =CGSizeMake(1500, 59);
[self.view layoutIfNeeded];
}
-(void)fillcalendar
{
buttonIndex=0;
for (UIButton *btn in uiButtonArray )
{
[btn removeFromSuperview];
}
[uiButtonArray removeAllObjects];
globalDate=currentDate;
// this is the placeholder for the calendar
// setting up the month title
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:#"MMMM yyyy"];
[monthLabel setText:[df stringFromDate:currentDate]];
NSDateComponents *components = [calendar components:NHWunits fromDate:currentDate];
// change for the first day
[components setDay:1];
// update the component
components = [calendar components:NHWunits fromDate:[calendar dateFromComponents:components]];
[components setDay:-[components weekday]+2];
int lessDay = [components day];
int month = [components month];
int year = [components year];
// extracting components from date
NSDateComponents *components3 = [calendar components:NHWunits fromDate:[NSDate date]];
int currentDateInteger=[components3 day];
monthInteger=[components3 month];
yearInteger=[components3 year];
CGFloat orgx=0,orgy=1.0f;
int m=month;
for (int week=0; week<6 && month==m; week++)
{
for (int d=0; d<7; d++)
{
[components setDay:lessDay];
int d =[[calendar components:NHWunits fromDate:[calendar dateFromComponents:components]] day];
m =[[calendar components:NHWunits fromDate:[calendar dateFromComponents:components]] month];
int y =[[calendar components:NHWunits fromDate:[calendar dateFromComponents:components]] year];
NSString *daysdate = [NSString stringWithFormat:#"%d-%d-%d",d,m,y];
NSDateFormatter *nwd =[[NSDateFormatter alloc]init];
[nwd setDateFormat:#"dd-MM-yyyy"];
NSDate *notdays =[nwd dateFromString:daysdate];
[nwd setDateFormat:#"EEE"];
NSString *WDays =[nwd stringFromDate:notdays];
UILabel *Weekdays =[self createLbl:WDays orgx:orgx orgy:orgy];
UIButton *button = [self createBtn:d orgx:orgx orgy:orgy Date:currentDate];
if (d==defaultDateInteger && defaultMonthInteger==m)
{
// globalButton=button;
}
NSString *isSunday =[NSString stringWithFormat:#"%d-%d-%d",d,m,y];
NSDate *date = [NSDate date];
NSDateFormatter *df = [[NSDateFormatter alloc]init];
[df setDateFormat:#"d-M-yyyy"];
NSString *cdate = [df stringFromDate:date];
NSLog(#"CURRENT DATE: %# \n %#", isSunday,cdate);
//Circle the Today's Date
if ([isSunday isEqualToString:cdate]) {
[button setBackgroundColor:[UIColor lightGrayColor]];
// [button.titleLabel setTextColor:[UIColor whiteColor]];
}
[Calendarscroll addSubview:button];
[Calendarscroll addSubview:Weekdays];
button.tag=buttonIndex;
[uiButtonArray addObject:button];
// [DayArray addObject:Weekdays];
buttonIndex++;
orgx+=46;
lessDay++;
}
}
}
- (UIButton*) createBtn:(int)day orgx:(CGFloat)orgx orgy:(CGFloat)orgy Date:(NSDate*)caldate
{
UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
NSDateFormatter *cMonth = [[NSDateFormatter alloc] init];
[cMonth setDateFormat:#"MMMM yyyy"];
NSDate *date = [NSDate date];
NSDateFormatter *df = [[NSDateFormatter alloc]init];
[df setDateFormat:#"dd-MM-yyyy"];
NSDateFormatter *dff = [[NSDateFormatter alloc]init];
[dff setDateFormat:#"d"];
NSDateFormatter *days =[[NSDateFormatter alloc]init];
[days setDateFormat:#"EEE"];
NSString *cdate1 = [dff stringFromDate:date];
NSLog(#"The single date is: %#",cdate1);
NSString *cdate = [df stringFromDate:date];
NSLog(#"df is: %#",cdate);
NSString *cdays =[days stringFromDate:date];
NSLog(#"The days are: %#",cdays);
[button setBackgroundColor:[UIColor colorWithRed:0.52 green:0.5 blue:0.12 alpha:0.8]];
button.titleEdgeInsets = UIEdgeInsetsMake(-14.0, -16.0, 0.0, 0.0);
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button setTitle:[NSString stringWithFormat:#"%d", day] forState:UIControlStateNormal];
[button.titleLabel setFont:[UIFont systemFontOfSize:16.0f]];
button.frame=CGRectMake(orgx, 28, 35, 30);
return button;
}
-(UILabel*) createLbl:(NSString*)Days orgx:(CGFloat)orgx orgy:(CGFloat)orgy
{
UILabel *Weekdays =[[UILabel alloc]initWithFrame:CGRectMake(orgx, 5, 35, 20)];
NSDateFormatter *cMonth = [[NSDateFormatter alloc] init];
[cMonth setDateFormat:#"MMMM yyyy"];
NSDate *Ndate = [NSDate date];
NSDateFormatter *df = [[NSDateFormatter alloc]init];
[df setDateFormat:#"dd-MM-yyyy"];
NSDateFormatter *days =[[NSDateFormatter alloc]init];
[days setDateFormat:#"EEE"];
NSString *cdate = [df stringFromDate:Ndate];
NSLog(#"df is: %#",cdate);
NSString *cdays =[days stringFromDate:Ndate];
NSLog(#"The days are: %#",cdays);
[Weekdays setBackgroundColor:[UIColor colorWithRed:0.52 green:0.5 blue:0.12 alpha:0.8]];
//Weekdays.titleEdgeInsets = UIEdgeInsetsMake(-14.0, -16.0, 0.0, 0.0);
[Weekdays setTextColor:[UIColor blackColor]];
[Weekdays setText:[NSString stringWithFormat:#"%#", Days]];
[Weekdays setFont:[UIFont systemFontOfSize:16.0f]];
return Weekdays;
}
-(void)CreateSection
{
sectionsData =[[NSMutableArray alloc]init];
for (int i=0; i<collectHW.count; i++)
{
/* [sectionsData addObject:[[NSMutableArray alloc] initWithObjects:[NSString stringWithFormat:#"Title: %#",[[collectHW objectAtIndex:i] valueForKey:#"name"]],[NSString stringWithFormat:#"DUE DATE: %#",[[collectHW objectAtIndex:i] valueForKey:#"deadlinedate"]],[NSString stringWithFormat:#"DESCRIPTION: %#",[[collectHW objectAtIndex:i] valueForKey:#"description"]],[NSString stringWithFormat:#"Tap to download attachment."],#"hasAttachment",nil]];
// [Sectiondata addObject:sectionarray];
NSLog(#"The description is: %#",sectionsData);*/
//for (int i =0; i<newsArray.count; i++)
if ([[[collectHW objectAtIndex:i] valueForKey:#"path"]stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:BLANK_STRING]].length!=0)
{
[sectionsData addObject:[[NSMutableArray alloc] initWithObjects:[NSString stringWithFormat:#"DESCRIPTION: %#",[[collectHW objectAtIndex:i] valueForKey:#"description"]],[NSString stringWithFormat:#"Tap to download attachment."],#"hasAttachment",nil]];
}
else
{
[sectionsData addObject:[[NSMutableArray alloc] initWithObjects:[NSString stringWithFormat:#"DESCRIPTION: %#",[[collectHW objectAtIndex:i] valueForKey:#"description"]], nil]];
}
/* if ([[[collectHW objectAtIndex:i] valueForKey:#"path"]stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:BLANK_STRING]].length!=0)
{
if ([[[collectHW objectAtIndex:i] valueForKey:#"name"]stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:BLANK_STRING]].length!=0)
{
if ([[[collectHW objectAtIndex:i] valueForKey:#"deadlinedate"]stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:BLANK_STRING]].length!=0)
{
if ([[[collectHW objectAtIndex:i] valueForKey:#"description"]stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:BLANK_STRING]].length!=0)
{
[sectionsData addObject:[[NSMutableArray alloc] initWithObjects:[NSString stringWithFormat:#"Title: %#",[[collectHW objectAtIndex:i] valueForKey:#"name"]],[NSString stringWithFormat:#"DUE DATE: %#",[[collectHW objectAtIndex:i] valueForKey:#"deadlinedate"]],[NSString stringWithFormat:#"DESCRIPTION: %#",[[collectHW objectAtIndex:i] valueForKey:#"description"]],[NSString stringWithFormat:#"Tap to download attachment."],#"hasAttachment",nil]];
NSLog(#"The description is: %#",sectionsData);
}else
{
[sectionsData addObject:[[NSMutableArray alloc] initWithObjects:[NSString stringWithFormat:#"Title: %#",[[collectHW objectAtIndex:i] valueForKey:#"name"]],[NSString stringWithFormat:#"DUE DATE: %#",[[collectHW objectAtIndex:i] valueForKey:#"deadlinedate"]],[NSString stringWithFormat:#"Tap to download attachment."],#"hasAttachment",nil]];
}
}else{////deadlinedate........
if ([[[collectHW objectAtIndex:i] valueForKey:#"description"]stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:BLANK_STRING]].length!=0)
{
[sectionsData addObject:[[NSMutableArray alloc] initWithObjects:[NSString stringWithFormat:#"Title: %#",[[collectHW objectAtIndex:i] valueForKey:#"name"]],[NSString stringWithFormat:#"DESCRIPTION: %#",[[collectHW objectAtIndex:i] valueForKey:#"description"]],[NSString stringWithFormat:#"Tap to download attachment."],#"hasAttachment",nil]];
NSLog(#"The description is: %#",sectionsData);
}else
{
[sectionsData addObject:[[NSMutableArray alloc] initWithObjects:[NSString stringWithFormat:#"Title: %#",[[collectHW objectAtIndex:i] valueForKey:#"name"]],[NSString stringWithFormat:#"Tap to download attachment."],#"hasAttachment",nil]];
}
}
}else
{//////name........
if ([[[collectHW objectAtIndex:i] valueForKey:#"deadlinedate"]stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:BLANK_STRING]].length!=0)
{
if ([[[collectHW objectAtIndex:i] valueForKey:#"description"]stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:BLANK_STRING]].length!=0)
{
[sectionsData addObject:[[NSMutableArray alloc] initWithObjects:[NSString stringWithFormat:#"DUE DATE: %#",[[collectHW objectAtIndex:i] valueForKey:#"deadlinedate"]],[NSString stringWithFormat:#"DESCRIPTION: %#",[[collectHW objectAtIndex:i] valueForKey:#"description"]],[NSString stringWithFormat:#"Tap to download attachment."],#"hasAttachment",nil]];
NSLog(#"The description is: %#",sectionsData);
}else
{
[sectionsData addObject:[[NSMutableArray alloc] initWithObjects:[NSString stringWithFormat:#"DUE DATE: %#",[[collectHW objectAtIndex:i] valueForKey:#"deadlinedate"]],[NSString stringWithFormat:#"Tap to download attachment."],#"hasAttachment",nil]];
}
}else{////deadlinedate........
if ([[[collectHW objectAtIndex:i] valueForKey:#"description"]stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:BLANK_STRING]].length!=0)
{
[sectionsData addObject:[[NSMutableArray alloc] initWithObjects:[NSString stringWithFormat:#"DESCRIPTION: %#",[[collectHW objectAtIndex:i] valueForKey:#"description"]],[NSString stringWithFormat:#"Tap to download attachment."],#"hasAttachment",nil]];
NSLog(#"The description is: %#",sectionsData);
}else
{
[sectionsData addObject:[[NSMutableArray alloc] initWithObjects:[NSString stringWithFormat:#"Tap to download attachment."],#"hasAttachment",nil]];
}
}
}
}else
{/////////path......
if ([[[collectHW objectAtIndex:i] valueForKey:#"name"]stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:BLANK_STRING]].length!=0)
{
if ([[[collectHW objectAtIndex:i] valueForKey:#"deadlinedate"]stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:BLANK_STRING]].length!=0)
{
if ([[[collectHW objectAtIndex:i] valueForKey:#"description"]stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:BLANK_STRING]].length!=0)
{
[sectionsData addObject:[[NSMutableArray alloc] initWithObjects:[NSString stringWithFormat:#"Title: %#",[[collectHW objectAtIndex:i] valueForKey:#"name"]],[NSString stringWithFormat:#"DUE DATE: %#",[[collectHW objectAtIndex:i] valueForKey:#"deadlinedate"]],[NSString stringWithFormat:#"DESCRIPTION: %#",[[collectHW objectAtIndex:i] valueForKey:#"description"]],nil]];
// NSLog(#"The description is: %#",sectionsData);
}else
{
[sectionsData addObject:[[NSMutableArray alloc] initWithObjects:[NSString stringWithFormat:#"Title: %#",[[collectHW objectAtIndex:i] valueForKey:#"name"]],[NSString stringWithFormat:#"DUE DATE: %#",[[collectHW objectAtIndex:i] valueForKey:#"deadlinedate"]],nil]];
}
}else{////deadlinedate........
if ([[[collectHW objectAtIndex:i] valueForKey:#"description"]stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:BLANK_STRING]].length!=0)
{
[sectionsData addObject:[[NSMutableArray alloc] initWithObjects:[NSString stringWithFormat:#"Title: %#",[[collectHW objectAtIndex:i] valueForKey:#"name"]],[NSString stringWithFormat:#"DESCRIPTION: %#",[[collectHW objectAtIndex:i] valueForKey:#"description"]],nil]];
// NSLog(#"The description is: %#",sectionsData);
}else
{
[sectionsData addObject:[[NSMutableArray alloc] initWithObjects:[NSString stringWithFormat:#"Title: %#",[[collectHW objectAtIndex:i] valueForKey:#"name"]],nil]];
}
}
}else
{//////name........
if ([[[collectHW objectAtIndex:i] valueForKey:#"deadlinedate"]stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:BLANK_STRING]].length!=0)
{
if ([[[collectHW objectAtIndex:i] valueForKey:#"description"]stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:BLANK_STRING]].length!=0)
{
[sectionsData addObject:[[NSMutableArray alloc] initWithObjects:[NSString stringWithFormat:#"DUE DATE: %#",[[collectHW objectAtIndex:i] valueForKey:#"deadlinedate"]],[NSString stringWithFormat:#"DESCRIPTION: %#",[[collectHW objectAtIndex:i] valueForKey:#"description"]],nil]];
// NSLog(#"The description is: %#",sectionsData);
}else
{
[sectionsData addObject:[[NSMutableArray alloc] initWithObjects:[NSString stringWithFormat:#"DUE DATE: %#",[[collectHW objectAtIndex:i] valueForKey:#"deadlinedate"]],nil]];
}
}else{////deadlinedate........
if ([[[collectHW objectAtIndex:i] valueForKey:#"description"]stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:BLANK_STRING]].length!=0)
{
[sectionsData addObject:[[NSMutableArray alloc] initWithObjects:[NSString stringWithFormat:#"DESCRIPTION: %#",[[collectHW objectAtIndex:i] valueForKey:#"description"]],nil]];
// NSLog(#"The description is: %#",sectionsData);
}else
{
[self showDropDownViewWithmessage:#"No homework is yet to display." title:#"Message" inView:self.view];
}
}
}
}*/
NSLog(#"The new data is: %#",sectionsData);
}
UIColor *sectionsColor = [UIColor colorWithRed:36.0f/255.0f green:158.0f/255.0f blue:110.0f/255.0f alpha:1.0f];
UIColor *sectionTitleColor = [UIColor whiteColor];
UIFont *sectionTitleFont = [UIFont fontWithName:#"Futura" size:24.0f];
EMAccordionSection *section;
// emTV.closedSectionIcon=[UIImage imageNamed:#"icon_down.png"];
// emTV.openedSectionIcon=[UIImage imageNamed:#"icon_up.png"];
for (int i = 0 ; i<collectHW.count; i++)
{
section = [[EMAccordionSection alloc] init];
[section setBackgroundColor:sectionsColor];
[section setItems:[sectionsData objectAtIndex:i]];
[section setTitle:[NSString stringWithFormat:#"%#(%#)",[[collectHW objectAtIndex:i] valueForKey:#"subjectname"],[[collectHW objectAtIndex:i] valueForKey:#"assignmenttype"]]];
[section setTitleFont:sectionTitleFont];
[section setTitleColor:sectionTitleColor];
[emTV addAccordionSection:section];
}
NSLog(#"The Section is: %#",section.title);
[remarksTable reloadData];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"emCell"];
NSMutableArray *items = [sectionsData objectAtIndex:indexPath.section];
UILabel *titleLbl = [[UILabel alloc] initWithFrame:CGRectMake(5.0f,0.0f,220.0f, 40.0f)];
[titleLbl setFont:[UIFont boldSystemFontOfSize:14.0f]];
[titleLbl setText:[items objectAtIndex:indexPath.row]];
[titleLbl setBackgroundColor:[UIColor clearColor]];
[titleLbl setTextColor:[UIColor blackColor]];
CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);
CGSize size = [[items objectAtIndex:indexPath.row] sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
CGFloat height = MAX(size.height+10, 40.0f);
[titleLbl setFrame:CGRectMake(30, titleLbl.frame.origin.y, 280.0f, height)];
titleLbl.numberOfLines=30;
[[cell contentView] addSubview:titleLbl];
[cell setBackgroundColor:[UIColor clearColor]];
return cell;
}
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
//TAHomeworksTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"homeworkCell"];
NSMutableArray *items = [sectionsData objectAtIndex:indexPath.section];
NSString *text = [items objectAtIndex:[indexPath row]];
CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);
CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
CGFloat height = MAX(size.height+15, 40.0f);
return height;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
NSString *text = [NSString stringWithFormat:#"%#(%#)",[[collectHW objectAtIndex:section] valueForKey:#"subjectname"],[[collectHW objectAtIndex:section] valueForKey:#"assignmenttype"]];
NSLog(#"The text is: %#",text);
CGSize constraint = CGSizeMake(250.0f - (CELL_CONTENT_MARGIN * 2), 20000.0f);
CGSize size = [text sizeWithFont:[UIFont boldSystemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
CGFloat height = MAX(size.height+35, 40.0f);
return height;
}
- (UIColor *)colorWithHexString:(NSString *)str_HEX alpha:(CGFloat)alpha_range{
int red = 0;
int green = 0;
int blue = 0;
sscanf([str_HEX UTF8String], "#%02X%02X%02X", &red, &green, &blue);
return [UIColor colorWithRed:red/255.0 green:green/255.0 blue:blue/255.0 alpha:alpha_range];
}
-(void)updateUI
{
emTV = [[EMAccordionTableViewController alloc] initWithTable:remarksTable];
[emTV setDelegate:self];
[self addCustomBackButtonWithNaviBarColor:[self colorWithHexString:#"#c3b395" alpha:1.0f]];
//[self addCustomBackButton];
if (IS_IOS7)
{
[remarksTable setSeparatorInset:UIEdgeInsetsZero];
}
[self addCustomBackButtonWithNaviBarColor:[self colorWithHexString:#"#006666" alpha:1.0f]];
NSMutableArray *menuindex = (NSMutableArray *)[SharedPreferenceUtil getNSObject:#"menuindexarray"];
[self addCutomTitleToCustomNavigationBar:[NSString stringWithFormat:#"%#",[(NSMutableArray *)[SharedPreferenceUtil getNSObject:#"appnamearray"]objectAtIndex:[[menuindex objectAtIndex:[(NSString *)[SharedPreferenceUtil getNSObject:#"selmenuitem"]integerValue]]integerValue]]]];
currentDate=[NSDate date];
globalDate=currentDate;
calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
//today = [[NSDate alloc] initWithTimeIntervalSinceNow:1];
NSDateComponents *components = [calendar components:NHWunits fromDate:currentDate];
defaultDateInteger=components.day;
[self fillcalendar];
// [self getdate];
// [self dateSelectedInPickerView];
[self getRemarks];
}
-(void)getRemarks
{
if ([self connected])
{
[self showLoadingViewWithMessage:#"Loading..."];
[[DPSAppService sharedInstance] getDataFromURL:[self getURL] responseBlock:^(NSDictionary *response)
{
if (response)
{
NSLog(#"%#",response);
homewokArray = [response valueForKey:#"studentassignment"];
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:#"dd-MM-yyyy"];
NSDate *CurrentDate =[NSDate date];
NSString *cDate =[df stringFromDate:CurrentDate];
NSLog(#" current Month date is: %#",cDate);
collectHW =[[NSMutableArray alloc]init];
for (int i=0; i<homewokArray.count; i++)
{
NSLog(#"New data is: %#",[[homewokArray objectAtIndex:i]valueForKey:#"date"]);
if ([cDate isEqualToString:[[homewokArray objectAtIndex:i]valueForKey:#"date"]])
{
[collectHW addObject:[homewokArray objectAtIndex:i]];
}
else
{
NSLog(#"No Homework today");
}
}
NSLog(#"Current data of homework is: %#",collectHW);
if (homewokArray.count==0)
{
[self showDropDownViewWithmessage:#"No homework is yet to display." title:#"Message" inView:self.view];
}else
{
[self CreateSection];
// [self showHomework];
}
}
else
{
[self showDropDownViewWithmessage:SERVER_ERROR title:ERROR inView:self.view];
}
[self hideLoadingViewWithSuccessMessage:LOGIN_SUCCESS];
[self addBottomView];
}];
}
else
{
}
}
-(NSString *)getURL
{
return [NSString stringWithFormat:#"%#%#%#classid=%#&academciyearid=%#§ionid=%#",[SharedPreferenceUtil getNSObject:#"baseerpurl"],URL,STUDENT_HOMEWORK,[[SharedPreferenceUtil getNSObject:STUDENT_DATA_JSON ]valueForKey:#"classid"],[[SharedPreferenceUtil getNSObject:STUDENT_DATA_JSON ]valueForKey:#"academciyearid"],[[SharedPreferenceUtil getNSObject:STUDENT_DATA_JSON ]valueForKey:#"sectionid"]];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
Add exceptional breakpoint and see how many objects are there in Array and from which index an object being taken out from that array,by doing this you will be able to find out and sort out the problem :)
You always have to return the correct value in numberOfRowsInSection method. GENERALLY, that value is the count of an array. If this is also your case then please debug your flow and check for inconsistencies. Whenever the count of the array is altered or changed, the tableview should be reloaded.
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:>] ;
// 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
My UITableView is not scrolling properly I am using customcell as
My cell for rowAtIndexPath looks like this:
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
CustomCellWeather *cell = (CustomCellWeather *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil) {
NSArray *topLevelObjects=[[NSBundle mainBundle] loadNibNamed:#"CustomCellWeather" owner:nil options:nil];
for(id currentObject in topLevelObjects) {
if([currentObject isKindOfClass:[UITableViewCell class]])
{
cell = (CustomCellWeather *)currentObject;
// cell = [[[CustomCellWeather alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
break;
}
}
}
int index = indexPath.row;
cell.dayDateLabel.textColor = [UIColor colorWithRed:126/255.0 green:212/255.0 blue:252/255.0 alpha:1];
if(index == 0) {
cell.contentView.backgroundColor = [UIColor colorWithRed:0 green:102/255.0 blue:179/255.0 alpha:0.5];
cell.otherCondition.text = #"";
cell.dayTempMin_HumidityLabel.text = #"";
cell.dayConditionLabel.text = #"";
cell.otherWind.text = #"";
cell.dayWindLabel.text = #"";
cell.dayDateLabel.text = #"Current";
cell.dayTempMaxLabel.text = [[[resCurrTempC stringByAppendingString:#"°C/"] stringByAppendingString:resCurrTempF] stringByAppendingString:#"°F"];
cell.todayCondition.text = resCurrWeatherDesc;
cell.currentWind.text = [[[currWindDir stringByAppendingString:#" at "] stringByAppendingString:currWindSpeed] stringByAppendingString:#"mph"];
cell.currentHumidity.text = [resHumidity stringByAppendingString:#"%"];
NSURL *url = [NSURL URLWithString:currIcon];
cell.dayImage.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
}else {
cell.hiddenLabel.text = #""; //represents todayCondition
cell.todayWind.text = #"";
cell.currentWind.text = #"";
cell.todayHumidity.text = #"";
cell.currentHumidity.text = #"";
if(index == 1) {
cell.contentView.backgroundColor = [UIColor colorWithRed:124/255.0 green:123/255.0 blue:123/255.0 alpha:0.5];
cell.dayDateLabel.text = #"Today";
}else{
//NSDate *today = [NSDate date];
NSString *dateString = [responseDate objectAtIndex:index-1];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
// this is imporant - we set our input date format to match our input string
// if format doesn't match you'll get nil from your string, so be careful
[dateFormatter setDateFormat:#"yyyy-MM-dd"];
dateFromString = [[NSDate alloc] init];
// voila!
dateFromString = [dateFormatter dateFromString:dateString];
[dateFormatter release];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:#"EEEE, MMM dd"];
NSCalendar *calender = [NSCalendar currentCalendar];
NSDateComponents *components = [calender components:( NSHourCalendarUnit ) fromDate:dateFromString];
//[components setHour:24*(index-1)];
dateFromString = [calender dateByAddingComponents:components toDate:dateFromString options:0];
NSString *stri = [formatter stringFromDate:dateFromString];
cell.contentView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
cell.dayDateLabel.text = stri;
//[dateFromString release];
[formatter release];
}
cell.dayTempMaxLabel.text = [[[[#"Max: " stringByAppendingString:[responseTempMaxC objectAtIndex:index-1]] stringByAppendingString:#"°C/"] stringByAppendingString:[responseTempMaxF objectAtIndex:index-1]] stringByAppendingString:#"°F"] ;
cell.dayTempMin_HumidityLabel.text = [[[[#"Min: " stringByAppendingString:[responseTempMinC objectAtIndex:index-1]] stringByAppendingString:#"°C/"] stringByAppendingString:[responseTempMinF objectAtIndex:index-1]] stringByAppendingString:#"°F"] ;
cell.dayConditionLabel.text = [responseWeatherDesc objectAtIndex:index-1];
cell.dayWindLabel.text = [[[[responseWindDirection objectAtIndex:index-1]stringByAppendingString:#" at "]stringByAppendingString:[responseWindspeedMiles objectAtIndex:index-1]] stringByAppendingString:#"mph"];
NSURL *url = [NSURL URLWithString:[responseWeatherIconUrl objectAtIndex:index-1]];
cell.dayImage.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
return cell;}
actually i am parsing weather news from a website
can u tell me how can i solve dis
read following link its may be help u
http://www.e-string.com/content/custom-uitableviewcells-interface-builder
http://blog.webscale.co.in/?p=284
http://www.icodeblog.com/2009/05/24/custom-uitableviewcell-using-interface-builder/