2

私のアプリは、インターネットから UITableViewCell に投稿をダウンロードしています。ユーザーがセルをタップすると、この記事を既読として設定する必要があります(Mail.appのように)。その方法がわかりません。データベース(「url | url | url」など)にURL(ユーザーがセルを押したとき)を追加し、詳細ビューを開きます。そして、UITableView に戻って、DB 内の既存の URL をチェックします。現在のテーブルは遅すぎます! 私を助けて、それを行うために私が使用できる他の方法を教えてもらえますか? mail.app のように。drawRect メソッドでカスタム セルとコードを使用しています。助けてください

     - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
        {
            NSString *CellIdentifier = [NSString stringWithFormat:@"%d",indexPath.row];
            NSMutableArray *array=[NSMutableArray array];
            if([[NSUserDefaults standardUserDefaults] objectForKey:@"readPostS"]!=nil)
    [array addObjectsFromArray:[[NSUserDefaults standardUserDefaults] objectForKey:@"readPostS"]];
            NSUInteger indexOfObject = [array count]>0?[array indexOfObject:[NSNumber numberWithInt:indexPath.row]]:100000;  //I add this, because row don't want update using updateRowAtIndexPath

            QuickCell *cell = (QuickCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            if (cell == nil || (indexOfObject!=NSNotFound && indexOfObject!=100000))
            {
                cell = [[[QuickCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
                cell.frame = CGRectMake(0.0, 0.0, 320.0, 68.0);
                cell.accessoryType = UITableViewCellAccessoryNone;
                if([self.subject count]>0)
            {
                [self.allImages addObject:[NSNull null]];
                NSString *userNameLJ = [NSString stringWithFormat:@"%@",[self.journalurl objectAtIndex:indexPath.row]];
                userNameLJ = [userNameLJ stringByReplacingOccurrencesOfString:@"http://"
                                                                   withString:@""];
                userNameLJ = [userNameLJ stringByReplacingOccurrencesOfString:@".livejournal.com"
                                                                   withString:@""];
                userNameLJ = [userNameLJ stringByReplacingOccurrencesOfString:@"community/"
                                                                   withString:@""];
                NSString *postURL = [NSString stringWithFormat:@"http://m.livejournal.com/read/user/%@/%@",userNameLJ,[self.ditemid objectAtIndex:indexPath.row]];


                NSMutableDictionary *dict = [NSMutableDictionary dictionary];
                [dict setObject:[self.subject objectAtIndex:indexPath.row] forKey:@"title"];
                [dict setObject:[Utilities replaceForCell:[Utilities flattenHTML:[self.entry objectAtIndex:indexPath.row]]] forKey:@"description"];

                if([[database executeQuery:@"SELECT * FROM read WHERE posts=?;",postURL] count]>0)
            {
                //if this post is read
                [dict setObject:[NSNumber numberWithBool:NO] forKey:@"highlighted"];
            }   
                else {
                    [dict setObject:[NSNumber numberWithBool:YES] forKey:@"highlighted"];
                }


            [dict setObject:[self.journalname objectAtIndex:indexPath.row] forKey:@"nick"];

            [cell setContentForCell:dict];

                BOOL trueOrFalse = [[self.allImages objectAtIndex:indexPath.row] isKindOfClass:[NSNull class]]?YES:NO;
            if(trueOrFalse)
        {
            if (tableView.dragging == NO && tableView.decelerating == NO)
            {
                    //if no image cached now, download it
                if(indexPath.row<6 && self.updating==YES)
                    [self startDownloading:indexPath];
                if(self.updating==NO)
                    [self startDownloading:indexPath];
            }

            }
            else
            {
                [cell setImageForCell:[self.allImages objectAtIndex:indexPath.row]];
        }

            }

                if(indexOfObject!=NSNotFound && indexOfObject!=100000)
                {
                       //delete this row from userdefaults
                    [array removeObjectAtIndex:indexOfObject];
                    if([array count]>0)
                        [[NSUserDefaults standardUserDefaults] setObject:array forKey:@"readPostS"];
                    else [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"readPostS"];

                }
            }


            return cell;
        }

//////////////////////////////////////////////////////////////
///////-(void)viewWillApear
//////////////////////////////////////////////////////////////
    NSMutableArray *readPosts = [NSMutableArray array];
                if([[NSUserDefaults standardUserDefaults] objectForKey:@"readPostS"]!=nil)
                {
                    [readPosts addObjectsFromArray:[[NSUserDefaults standardUserDefaults] objectForKey:@"readPostS"]];
                    self.read = (NSMutableArray*)[database executeQuery:@"SELECT * FROM read;"];
                    for(int i=0;i<[readPosts count];i++)
                    {

                    [self.myTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:[[readPosts objectAtIndex:i] intValue] inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
                    }
                }

///////////////////////////////////////////////
///////THIS FILE OPENS POSTS FOR READING
///////////////////////////////////////////////
if([[database executeQuery:@"SELECT * FROM read WHERE posts=?;",self.postURL] count]==0)
    {
        [database executeNonQuery:@"INSERT INTO read VALUES (?);",self.postURL];

        NSMutableArray *defaults = [NSMutableArray array];
        if([[NSUserDefaults standardUserDefaults] objectForKey:@"readPostS"]!=nil)
            defaults = [NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults] objectForKey:@"readPostS"]];
        [defaults addObject:[NSNumber numberWithInt:self.currentIndex]];
        [[NSUserDefaults standardUserDefaults] setObject:defaults forKey:@"readPostS"];
    }

Ok。私のコードは悪いので、ここで何をしているのか理解できます)他の質問に答えてください。非表示のセルを更新するにはどうすればよいですか? ユーザーは、一度に 6 つのセルしか表示しません。たとえば、10 個のセルを更新する必要があります。どのように?または、セルが既に存在する場合、どのようにセルをリロードしますか? まあ言ってみれば -

NSString *CellIdentifier = [NSString stringWithFormat:@"%d",indexPath.row];
QuickCell *cell = (QuickCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        cell = [[[QuickCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        cell.frame = CGRectMake(0.0, 0.0, 320.0, 68.0);
        cell.accessoryType = UITableViewCellAccessoryNone;


.........}

現在、セルが存在し、データのリロードを呼び出しても何も起こりません。また、セルには一意の識別子と ixists があるため、 reloadCellAtIndexPath も機能しません。

セルをリロードして DRAWRECT を再度呼び出すにはどうすればよいですか?))

4

2 に答える 2

0

コードをに追加することで、この機能を実装できます。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

//Add the indexPath.row values in an array.
}

カスタム機能(未読の場合はタイトルを太字で表示するなど)をに追加します

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

//Check if the indexPath.row is available in the array
//If yes then Normalize the fonts
//Else Keep them BOLD.

}
于 2010-12-30T12:07:01.110 に答える
0

実際に描画を行っている場合を除き、 に実装しないでくださいdrawRect:。あなたが特定のコードであるかどうかはわかりません。そのため、あなたの場合は正しくない可能性があります。

テーブル全体 (すべてのセル) をリロードするには、UITableView の- (void)reloadData

特定のセルをリロードするには、UITableView を見て、- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animationそれを使用して問題のセルをリロードします。

于 2010-12-30T16:24:31.537 に答える