I cant refresh tableView it is crashing without any exception.i am placing my code below.please let me know where i have gone wrong..
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 103;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row==[self.NewsArray count])
{
MoreLoadingViewCell *cell = (MoreLoadingViewCell *)[tableView dequeueReusableCellWithIdentifier:@"MyCell"];
if(cell==nil)
{
[[NSBundle mainBundle] loadNibNamed:@"MoreLoadingViewCell" owner:self options:nil];
cell = moreViewCell;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
//cell.backgroundView=nil;
}
return cell;
}
else
{
NewsCell *newsCell = (NewsCell *)[tableView dequeueReusableCel开发者_JAVA百科lWithIdentifier:@"NewsCell"];
if (newsCell == nil)
{
NSLog(@"create adcell object");
[[NSBundle mainBundle] loadNibNamed:@"NewsCell" owner:self options:nil];
newsCell=newsCellobject;
}
NewsObjectClass *object;
object=[self.NewsArray objectAtIndex:indexPath.row];
NSString *title=[object valueForKey:@"title"];
NSString *description=[object valueForKey:@"Description"];
NSString *dateString=[object valueForKey:@"NewsDate"];
newsCell.secondLabel.text=title;
newsCell.thirdLabel.text=description;
NSDateFormatter *dateFormatter=[[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
NSDate *date=[dateFormatter dateFromString:dateString];
[dateFormatter setDateFormat:@"YYYY MMM,dd hh:mm a"];
NSString *date_new=[dateFormatter stringFromDate:date];
NSLog(@"date is------ %@",date_new);
newsCell.DateLabel.text=date_new;
return newsCell;
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"-----------------array count is----------------------- %d",[self.NewsArray count]);
if ([self.NewsArray count] == 0)
{
return 0;
}
return [self.NewsArray count]+1;
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
if(refreshing)
{
NSLog(@"I am a big BUG, hehe hahahaha");
[spinner startAnimating];
[self performSelector:@selector(getDetails:) withObject:@"0" afterDelay:1.0];
//self.refreshing=NO;
}
}
- (void) scrollViewDidScroll:(UIScrollView *)scrollView{
tempView.frame = CGRectMake(0,-80 - scrollView.contentOffset.y , 320,80);
if(scrollView.contentOffset.y < -60)
{
lbl.text = @"Release to Update";
}
else
{
lbl.text = @"Pull down to Update";
}
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
if(scrollView.contentOffset.y<-60 && !refreshing)
{
refreshing=YES;
}
}
`
Post your crash log, Did you tried to debug the code by placing break points? After a quick review of your code I noticed that you are not releasing the NSDateFormatter *dateFormatter initialized inside the - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath method. This ll result in a huge memory leak. Also NSLog following variables to check whether they have expected values or nil.
NSString *title=[object valueForKey:@"title"];
NSString *description=[object valueForKey:@"Description"];
NSString *dateString=[object valueForKey:@"NewsDate"];
try NSZombieEnabled environment variable and debug with device. you will find the actual reason for crash.
精彩评论