-4

ここに私のコードがあります:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (isPurchased == NO) {

        return [UITableviewExample count];
        [UITableviewExample release];
    }
    else
    {
        return [UITableviewExample2 count];
        [UITableviewExample2 release];
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

        if (isPurchased == NO) {

            cell.textLabel.text = [UITableviewExample objectAtIndex:indexPath.row];
            [UITableviewExample release];
        }
        else {
            cell.textLabel.text = [UITableviewExample2 objectAtIndex:indexPath.row];
            [UITableviewExample2 release];

        }
    }

    return cell;
}

誰が私を助けてくれますか? アプリ内購入が成功した後、変更はありません。私が使用する場合

-(IBAction)test
{
    if (isPurchased == yes) {
        buyButton.hidden = yes;
    }
}

よく働く。私は2つのアプリ、アプリ内購入を試しました。非表示にしたり、ラベルのテキストを変更したりしても、すべてうまく機能します。UITableViewのアプリ内購入を機能させるにはどうすればよいですか? アプリ内購入が成功した後に行を変更したい。エラーはどこにありますか? ありがとうございました。

4

2 に答える 2

1

少なくとも、numberOfRowsInSection(コードがステートメントに到達するreleaseことはありませんが、とにかくそうしたくないcellForRowAtIndexPath場所) と (不適切なステートメントを実行していreleaseて、セルがこれまでにあった場合に論理バグがある場所) に対するいくつかの明らかな編集正常にデキューされました):

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (isPurchased == NO) {
        return [UITableviewExample count];
        // [UITableviewExample release];
    }
    else
    {
        return [UITableviewExample2 count];
        // [UITableviewExample2 release];
    }

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    // this was in the above "if (cell == nil)" block, but should be outside of it

    if (isPurchased == NO) {
        cell.textLabel.text = [UITableviewExample objectAtIndex:indexPath.row];
        // [UITableviewExample release];
    }
    else {
        cell.textLabel.text = [UITableviewExample2 objectAtIndex:indexPath.row];
        // [UITableviewExample2 release];
    }

    return cell;
}

スタイル的には、明らかに変数UITableviewExampleともありますUITableviewExample2が、適切なプログラミング スタイルの問題として、変数名は小文字で始める必要があります (例: tableviewExampleand ) tableviewExample2

質問の内容として、これらのNSArray(またはNSMutableArray) オブジェクトがどのように初期化されているかを示す必要があります。問題は上記のコードではなく、これらの配列の母集団にある可能性があります。

ただし、Guntis による優れた観察によると、アプリ内購入後にテーブルの変更が表示されないという問題がある場合は、reloadData.

于 2012-09-01T06:46:18.427 に答える
1

tableView の reloadData を呼び出してみてください - 通知を受け取ったら、アプリ内購入が行われました。

[tableView reloadData];

またはアニメーション付き:

[tableView reloadSections:0 withRowAnimation:UITableViewRowAnimationFade];
于 2012-09-01T06:44:29.847 に答える