【问题标题】:Problem With UitableView RefreshingUtableView 刷新问题
【发布时间】:2011-06-18 07:32:31
【问题描述】:

我无法刷新 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;
        }


    }

`

【问题讨论】:

  • @RahulVyas 我在调试时没有收到任何崩溃错误。它在移动设备中崩溃

标签: iphone objective-c uitableview scrollview


【解决方案1】:

发布您的崩溃日志,您是否尝试通过放置断点来调试代码?在快速查看您的代码后,我注意到您没有发布在 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 方法内初始化的 NSDateFormatter *dateFormatter。这将导致巨大的内存泄漏。还 NSLog 跟踪变量以检查它们是否具有预期值或 nil.

NSString *title=[object valueForKey:@"title"];
NSString *description=[object valueForKey:@"Description"];
NSString *dateString=[object valueForKey:@"NewsDate"];

【讨论】:

  • 嗨 adarsh 我发布了 dateFormatter。但我的问题是应用程序在调试时没有崩溃。但调试后它崩溃了。你能帮我解决这个问题
  • 请把完整的代码发给我。我会调查一下。
  • 崩溃后键入 bt 并在控制台中按回车键。它将为您提供有关崩溃的更多详细信息。
  • 嗨,我在上面的链接中粘贴了代码。请参阅 .pastebin.com/bXispj8i
【解决方案2】:

尝试使用 NSZombieEnabled 环境变量并使用设备进行调试。你会找到崩溃的真正原因。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-05
    • 2011-08-04
    • 2011-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多