2

解決済み:以下の私の答え(および考えられる説明)を参照してください。

iOS 5.1 デバイスで動作するアプリを作成していますが、iOS 5.0 デバイスでは動作しません。5.1 では機能するが 5.0 では機能しないトラブル コードを次に示します。

- (void) expandIndexPath: (NSIndexPath *) indexPath afterDelay: (BOOL) delay
{
    NSIndexPath *oldSelectedIndexPath = [NSIndexPath indexPathForRow:self.mySelectedIndex inSection:0];
    self.mySelectedIndex= indexPath.row; 
//  [self.myTableView beginUpdates];
    [self.myTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:self.mySelectedIndex inSection:0], oldSelectedIndexPath,nil] withRowAnimation:UITableViewRowAnimationNone]; 
//  [self.myTableView endUpdates];
}

さらに興味深いことに、reloadRowsAtIndexPaths行をに置き換えると、iOS 5.0 でも動作し[self.myTableView reloadData];ます。どうしてこれなの?5.0 には reloadRowsAtIndexPaths 行に関するバグがありましたか? 5.0 で行の有無にかかわらず試してみましたがbegin/endUpdates、どちらも機能しません。

編集:より具体的には、iOS 5 でアプリを実行すると、次のエラーでクラッシュします。

*でのアサーションの失敗-[_UITableViewUpdateSupport _computeRowUpdates]/SourceCache/UIKit/UIKit-1912.3/UITableViewSupport.m:386 [プロセス 7171 スレッド 0x1c03 への切り替え]

捕捉されなかった例外 ' NSInternalInconsistencyException' が原因でアプリを終了しています。理由: 'テーブル ビューの更新が無効です。アプリケーションは、データ ソースによって提供された状態と矛盾するテーブル ビューへの更新を要求しました。

編集: ここに私の UITableViewDataSource メソッドがあります。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    //I am positive that this will ALWAYS return the number (it never changes)
    return self.myCellControllers.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //I cache my table view cells, thus each time this method gets called it will 
    // return the exact same cell. Yes, I know that most of the time I should be dequeing
    // and reusing cells; just trust me that this time, it's best for me to cache them
    // (There are very few cells so it doesn't really matter)
    CellController *controller = [self.myCellControllers objectAtIndex:indexPath.row];
    return controller.myCell;
}

- numberOfSectionsInTableView: always returns 1;

唯一の興味深い方法は

- (CGFloat)tableView:(UITableView *)aTableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == self.mySelectedIndex)
    {
        return DEFAULT_CELL_HEIGHT + self.expandSize;
    }
    else
    {
        return DEFAULT_CELL_HEIGHT;
    }
}

プログラムのこの部分がどのように機能するかを簡単に説明すると、ユーザーがセルをタップすると、セルが画面の上部にスクロールします。画面の上部にあると、インデックスが設定されself.mySelectedIndex、展開されます (高くなります)。

4

1 に答える 1

3

うまくいく解決策を見つけました。expandIndexPathメソッドをこれに変更すると、機能します:

- (void) expandIndexPath: (NSIndexPath *) indexPath afterDelay: (BOOL) delay {
    [self.myTableView beginUpdates];
    NSIndexPath *oldSelectedIndexPath = [NSIndexPath indexPathForRow:self.mySelectedIndex inSection:0];
    self.mySelectedIndex= indexPath.row;
    if(oldSelectedIndexPath.row >= 0)
    {
        [self.myTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:self.mySelectedIndex inSection:0],oldSelectedIndexPath, nil] withRowAnimation:UITableViewRowAnimationNone]; 
    }
    else 
    {
        [self.myTableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:self.mySelectedIndex inSection:0],nil] withRowAnimation:UITableViewRowAnimationNone]; 
    }
    [self.myTableView endUpdates]; 
}

私が知る限り、問題はoldSelectedIndexPath時々負の行値で設定されていたことでした。したがって、負の行で indexPath をリロードしようとすると、iOS 5.0 でクラッシュしました。iOS 5.1 ではこれが修正され、より多くのエラー チェックが行われるようです。

于 2012-07-18T21:32:39.943 に答える