1

EventEditViewController次のコードで新しいイベントを追加するために を初期化しています。

- (void)presentEventEditViewControllerWithEventStore:(EKEventStore*)eventStore
{
    EKEventEditViewController* vc = [[EKEventEditViewController alloc] init];
    vc.eventStore = eventStore;
    vc.delegate = self; // Probably self


    EKEvent* event = [EKEvent eventWithEventStore:eventStore];
    event.title = @"";
    event.startDate = [NSDate date];
    event.endDate = [NSDate date];
    event.URL = [NSURL URLWithString:@""];
    event.notes = @"";
    event.allDay = NO;
    vc.event = event;

    vc.editViewDelegate = self;

    [self presentViewController:vc animated:NO completion:nil];
}

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    UITableView *tableView = ((UITableViewController *)viewController).tableView;

    if ([viewController isKindOfClass:[UITableViewController class]]) {
        //((UITableViewController *)viewController).tableView.backgroundColor = [UIColor clearColor];
        for (NSInteger j = 0; j < [tableView numberOfSections]; ++j)
        {
            for (NSInteger i = 0; i < [tableView numberOfRowsInSection:j]; ++i)
            {
                UITableViewCell *cell = [tableView cellForRowAtIndexPath:[NSIndexPath     indexPathForRow:i inSection:j]];

                    cell.backgroundView =  [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Background-1.png"]];
                    cell.textLabel.textColor = [UIColor whiteColor];
                    cell.textLabel.backgroundColor = [UIColor clearColor];
                }
            }
    }
 }

UITableViewCellUITableViewは正常に表示されますが、iPhoneの画面に表示されなくなるまでスクロールを開始してからスクロールバックすると、TableViewCellその画像が忘れられて標準に変わりますUITableViewCell(背景画像やカスタマイズなし)。

スクロール前のスクリーンショット: http://postimg.org/image/vzlj3t5o9/ )

スクロール後のスクリーンショット: ( http://postimg.org/image/c30836v2v/ )

この問題を解決するにはどうすればよいですか?

前もって感謝します!

4

1 に答える 1

0

tableView:cellForRowAtIndexPath:いくつかの理由から、aa 実装のコンテキスト外でテーブル セルの外観を管理しようとするべきではありません。しかし、EKEventEditViewControllerのワークフローに含まれるさまざまなビュー コントローラをサブクラス化できないため、これらのメソッドの実装を通常の方法で作成することはできません。ただし、Objective-C のリフレクションとランタイムの一部を使用して、独自のUITableViewDataSource実装を挿入できます。

基本的な考え方は、テーブル ビューのデータ ソースをユーザーが制御するものに切り替えることですが、それでもイベント キット UI フレームワークによって提供される実装に依存し、それらが返すセルに視覚的な微調整のみを適用します。以下は、私のインターフェースと実装ですFakeTableViewDataSource

@interface FakeTableViewDataSource : NSObject <UITableViewDataSource>

@property (nonatomic) id<UITableViewDataSource> realDataSource;

@end

@implementation FakeTableViewDataSource


- (BOOL)respondsToSelector:(SEL)aSelector
{
    BOOL responds = [super respondsToSelector:aSelector];
    if (!responds && self.realDataSource) {
        responds = [self.realDataSource respondsToSelector:aSelector];
    }

    return responds;
}


- (void)forwardInvocation:(NSInvocation *)anInvocation
{
    if ([self.realDataSource respondsToSelector:[anInvocation selector]]) {
        [anInvocation invokeWithTarget:self.realDataSource];
    }
    else {
        [super forwardInvocation:anInvocation];
    }
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [self.realDataSource tableView:tableView cellForRowAtIndexPath:indexPath];
    cell.textLabel.textColor = [UIColor greenColor];
    return cell;
}

@end

アプリの特定の視覚的な微調整を実装するために実装しますtableView:cellForRowAtIndexPath:。機能するかどうかは明らかだったので、テキスト ラベルの色を選択しました。

ここで、UINavigationControllerDelegateメソッドで、セルを反復する代わりに、データ ソースを交換します。私の実装は次のとおりです。

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if ([viewController isKindOfClass:[UITableViewController class]]) {
        UITableView *tableView = ((UITableViewController *)viewController).tableView;
        if (![tableView.dataSource isKindOfClass:[FakeTableViewDataSource class]]) {
            FakeTableViewDataSource *fakeDataSource = [[FakeTableViewDataSource alloc] init];
            fakeDataSource.realDataSource = tableView.dataSource;
            tableView.dataSource = fakeDataSource;
            [self.fakeDataSources addObject:fakeDataSource];
        }
    }
}

このような方法でフレームワークを改ざんすることは、保守性の観点およびアプリ ストアの承認の観点から潜在的に危険であると言わなければなりません。そのため、このような手法を使用するときは注意してください。

于 2013-08-11T09:47:15.887 に答える