收到推送通知时从视图中选择一行

问题描述:

我试图从收到推送通知时从表视图中选择一行。收到推送通知时从视图中选择一行

我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启动选项启动并显示表格视图。

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

请帮助我这个。我是ios编程的新手。

谢谢。

您可以在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 
} 

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

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

希望这会有所帮助。

+0

我在尝试你的方法,是否需要在tableview方法中添加第一行? –

+0

只需在书签列表“viewDidLoad”中添加该行即可。 – HRM

+0

在添加评论后得到了这个想法:P –

使用的UITableView类方法:

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

这会在你给它indexPath返回小区。

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

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

我是新的,如果你不介意你能否详细说明或指导我一个链接或教程? –

+0

您需要结合2个答案。像HRM建议的那样设置通知,使用我的UITableView方法来选择你的单元格。 – Jasper

+0

你可以在http://*.com/questions/4518723/how-to-highlight-a-row-in-a-uitableview – Jasper