问题描述
|
我无法刷新tableView,没有任何异常崩溃。我将代码放在下面。请让我知道我哪里出了错。
-(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 dequeueReusableCellWithIdentifier:@\"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;
}
}
`
解决方法
发布崩溃日志,您是否尝试过通过放置断点来调试代码?快速浏览代码后,我注意到您没有释放在-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath方法中初始化的NSDateFormatter * dateFormatter。这将导致巨大的内存泄漏。另外NSLog以下变量检查它们是否具有期望值或零。il1ѭ
, 尝试使用NSZombieEnabled环境变量并使用设备进行调试。您会找到崩溃的实际原因。