Проблема с обновлением UitableView - PullRequest
0 голосов
/ 18 июня 2011

Я не могу обновить 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;
        }


    }

`

Ответы [ 2 ]

1 голос
/ 18 июня 2011

Разместите свой журнал сбоев. Вы пытались отлаживать код, устанавливая точки останова?После быстрого просмотра вашего кода я заметил, что вы не выпускаете NSDateFormatter * dateFormatter, инициализированный внутри - (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) метод indexPath.Это приведет к огромной утечке памяти.Также NSLog следуйте за переменными, чтобы проверить, имеют ли они ожидаемые значения или ноль. NSString *title=[object valueForKey:@"title"]; NSString *description=[object valueForKey:@"Description"]; NSString *dateString=[object valueForKey:@"NewsDate"];

0 голосов
/ 18 июня 2011

попробуйте переменную окружения NSZombieEnabled и выполните отладку на устройстве. Вы найдете фактическую причину аварии.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...