目前我的应用程序收到有关RSS提要更新的通知。如果用户从通知中打开应用程序,它将打开到正确的视图控制器。如果用户不确认通知并从应用程序图标打开应用程序,则当用户在应用程序内打开菜单时,该rss供稿的表格视图单元格带有带有applicationIconBadgeNumber的徽章图标。选中该行后,该单元格上的徽章将消失,并重置applicationIconBadgeNumber。我的问题是关于想要发送有关应用内其他信息的通知,如会员优惠。我如何区分表视图中的哪一行获得徽章?假设用户收到关于会员福利的通知。我希望徽章出现在表格视图的成员权益行中,但是如果有来自RSS提要的通知,请标记适当的行。UITableView Cell中的通知徽章
这是我目前如何为RSS提要行添加徽章。
在didSelectRowAtIndexPath方法if (!(indexPath.row == 0))
{
cell.accessoryView = nil;
}
badgeNumber = [NSString stringWithFormat:@"%ld", (long)[[UIApplication sharedApplication]applicationIconBadgeNumber]];
actionAlertBadge = [JSCustomBadge customBadgeWithString:badgeNumber withStringColor:[UIColor whiteColor] withInsetColor:[UIColor redColor] withBadgeFrame:NO withBadgeFrameColor:[UIColor redColor] withScale:1.0 withShining:NO withShadow:NO];
actionAlertBadge.frame = CGRectMake(83, 6, 30, 30);
if ([badgeNumber isEqualToString:@"0"])
{
actionAlertBadge.hidden = YES;
}
if (actionAlertBadge.hidden == NO)
{
if (indexPath.section == 0)
{
if (indexPath.row == 0)
{
cell.accessoryView = actionAlertBadge;
}
}
}
:
中的cellForRowAtIndexPathif (indexPath.row == 0)
{
ActionAlertsViewController *actionAlerts = [[ActionAlertsViewController alloc]initWithStyle:UITableViewStylePlain];
WebViewController *wvc = [[WebViewController alloc]init];
[actionAlerts setWebViewController:wvc];
[[UAPush shared] resetBadge];
actionAlertBadge.hidden = YES;
[tableView reloadData];
navController = [[KFBNavControllerViewController alloc]initWithRootViewController:actionAlerts];
[UIView transitionWithView:appDelegate.window
duration:0.5
options:UIViewAnimationOptionTransitionFlipFromRight
animations:^{
appDelegate.window.rootViewController = navController;
}
completion:nil];
}
编辑:这里是我正在努力做到这一点,但它不工作,因为在我的表视图我notificationType串空值。
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
UA_LINFO(@"Received remote notification: %@", userInfo);
// Send the alert to UA so that it can be handled and tracked as a direct response. This call
// is required.
[[UAPush shared]appReceivedRemoteNotification:userInfo applicationState:application.applicationState];
// Optionally provide a delegate that will be used to handle notifications received while the app is running
// [UAPush shared].delegate = your custom push delegate class conforming to the UAPushNotificationDelegate protocol
// Reset the badge after a push received (optional)
[[UAPush shared] resetBadge];
NSDictionary *apsInfo = [userInfo valueForKey:@"aps"];
NSString *alertMsg = @"";
if ([apsInfo valueForKey:@"alert"] != NULL) {
alertMsg = [apsInfo valueForKey:@"alert"];
if ([alertMsg containsString:@"ACTION ALERT"]) {
notificationType = @"action alert";
}
else if ([alertMsg containsString:@"MEMBER BENEFIT"]) {
notificationType = @"member benefit";
}
}
}
的cellForRowAtIndexPath:
KFBAppDelegate *appDelegate = (KFBAppDelegate *)[[UIApplication sharedApplication]delegate];
NSString *notificationType = appDelegate.notificationType;
// NSLog(@"notificationType menu table: %@", notificationType);
badgeNumber = [NSString stringWithFormat:@"%ld", (long)[[UIApplication sharedApplication]applicationIconBadgeNumber]];
actionAlertBadge = [JSCustomBadge customBadgeWithString:badgeNumber withStringColor:[UIColor whiteColor] withInsetColor:[UIColor redColor] withBadgeFrame:NO withBadgeFrameColor:[UIColor redColor] withScale:1.0 withShining:NO withShadow:NO];
actionAlertBadge.frame = CGRectMake(83, 6, 30, 30);
if ([badgeNumber isEqualToString:@"0"]) {
actionAlertBadge.hidden = YES;
}
if (actionAlertBadge.hidden == NO) {
if ([notificationType isEqualToString:@"action alert"]) {
if (indexPath.section == 0) {
if (indexPath.row == 0) {
cell.accessoryView = actionAlertBadge;
}
}
}
else if ([notificationType isEqualToString:@"member benefit"]) {
if (indexPath.section == 0) {
if (indexPath.row == 5) {
cell.accessoryView = actionAlertBadge;
}
}
}
}
您可以根据单元格的属性来选择,例如if(cell.title == @“RSS”){do this}。 – 2014-11-05 15:56:59
@FawadMasud,我知道。问题是确定通知的内容,以便正确的单元格被标记。 – raginggoat 2014-11-05 16:12:59