目前我的應用程序收到有關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