【问题标题】:select a row from view when a push notification is received收到推送通知时从视图中选择一行
【发布时间】:2013-07-16 03:18:40
【问题描述】:

收到推送通知时,我正在尝试从表格视图中选择一行。

我有 myprojectAppDelegate.h

#import <UIKit/UIKit.h>
#import "iw.h"
#import "Bookmark.h"


@interface myprojectAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
    UIWindow               *window;
    UITabBarController     *tabBarController;
    UINavigationController *navigationController;
    NSMutableArray                  *tableData;
    NSMutableArray                  *imagesList;
    IBOutlet Bookmark               *tableCell;
}

@property (nonatomic, retain) IBOutlet UIWindow               *window;
@property (nonatomic, retain) IBOutlet UITabBarController     *tabBarController;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property(nonatomic, retain) NSMutableArray                  *tableData;
@property(nonatomic, retain) NSMutableArray                  *imagesList;

- (BOOL)getIsLaunched;
- (void)showService;
- (void)showMessage;
- (void) loadLogoList;
+ (const NSString*)getVersion;
+ (const NSString*)getXMLversionURL;
+ (NSMutableDictionary *)logos;
+ (void)setLogos:(NSMutableDictionary *)newDictionary;
- (void)checkVersion;

@end

并在 myprojectAppDelegate.m 文件中实现 didReceiveRemoteNotification 但是当应用程序在启动选项后启动时,tableview 是在另一个类 bookmarklist.m 中实现的,它会导航到 bookmarklist.m 并显示 table view。

我想访问位于bookmarklist.m 中的表格视图,并在收到推送通知时选择表格中的一行。

请帮我解决这个问题。我是 ios 编程新手。

谢谢。

【问题讨论】:

    标签: iphone ios ios4


    【解决方案1】:

    使用 UITableView 类方法:

    - (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath

    这将返回您给它的 indexPath 处的单元格。

    如果你只想选择单元格,使用这个类方法:

    - (void)selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition
    

    【讨论】:

    • 我是新手,如果您不介意您能详细说明或指导我找到链接或教程吗?
    • 您将需要合并 2 个答案。像 HRM 建议的那样设置通知,使用我的 UITableView 方法来选择您的单元格。
    • 您可以在stackoverflow.com/questions/4518723/…找到更多关于如何选择您的单元格的信息
    • 太好了,很高兴能帮到您
    【解决方案2】:

    您可以像这样在 bookmarklist.m 类中添加观察者方法

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(newMessageReceived:) name:@"NEWMESSAGE" object:nil];
    

    并在同一个类中添加这个观察者方法

    -(void)newMessageReceived:(NSNotification *) notification{
           //Here you can select the row you want to be selected
    }
    

    然后在appDelegate 文件中的didReceiveRemoteNotification 中,发布这样的通知并在对象参数中传递您要发布的数据。

    [[NSNotificationCenter defaultCenter] postNotificationName:@"NEWMESSAGE" object:nil]; 
    

    希望这会有所帮助。

    【讨论】:

    • 我正在尝试你的方法,我需要在tableview方法中添加第一行吗?
    • 在添加评论后得到了这个想法:P
    • 我也可以从 didReceiveRemoteNotification 向这个方法发送一个整数变量 -(void)newMessageReceived:(NSNotification *) 通知吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多