点击通知时显示UITableViewCell中的相应内容?

时间:2015-01-16 09:46:07

标签: ios objective-c uitableview notifications

我使用CustomCell创建了一个UITableView。当单击视图顶部的按钮时,会创建一个本地通知并更新表视图。如果应用程序未处于运行状态,则会在banner中显示通知。单击时banner如何启动相应的更新UItableviewcell。需要帮助......

3 个答案:

答案 0 :(得分:1)

如果您的应用程序未运行,点击横幅后,您将在选项词典中的应用程序:didFinishLaunchingWithOptions:中通过键 UIApplicationLaunchOptionsLocalNotificationKey 接收本地通知。因此,您需要在应用开始时检查此密钥,并在出现本地通知时显示正确的单元格。

答案 1 :(得分:0)

您可以使用application:didFinishLaunchingWithOptions方法接收UILocalNotification并更新您的表格视图,您可以从此方法发布NSNotification。

答案 2 :(得分:0)

@ sha007,在你的应用开始时,你必须写下代码,

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.

    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge
                                                                                         |UIRemoteNotificationTypeSound
                                                                                         |UIRemoteNotificationTypeAlert) categories:nil];

    [[UIApplication sharedApplication] registerUserNotificationSettings:settings];

    // Handle launching from a notification
    UILocalNotification *localNotif =
    [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
    if (localNotif) {
        NSLog(@"Handle launching-> Recieved Notification ");
        localNotif.applicationIconBadgeNumber = 0;// set here the value of badg

        dicttemp=[NSDictionary new];
        dicttemp=[NSDictionary dictionaryWithObject:[localNotif.userInfo valueForKey:@"sent"] forKey:@"sent"];

        //Here you can get dictionary from Local Notification(eg.localNotif.userInfo) & using it , Navigate to View Controller & then Reload Data ..
    }
    return YES;
}

<强> &安培;如果您的应用是Foregroung模式意味着它的运行然后使用下面的代码..

- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
    // Handle the notificaton when the app is running
    NSLog(@"Handle the notificaton when the app is running -> Recieved Notification %@",notif);

    notif.applicationIconBadgeNumber = 0;// set here the value of badge

    dicttemp=[NSDictionary new];
    dicttemp=[NSDictionary dictionaryWithObject:[notif.userInfo valueForKey:@"sent"] forKey:@"sent"];

}