Versuchen Sie dies, ich hoffe, es wäre hilfreich für Sie !!!
In viewcontroller.m Datei
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
myData = [[NSMutableArray alloc]init];
myData = [[NSMutableArray alloc]initWithObjects:@"india",@"Japan",@"pakistan",@"srilanka", nil];
_mytableView.delegate = self;
_mytableView.dataSource = self;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)viewWillAppear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedNotification:)name:@"NOTIFICATION" object:nil];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return myData.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *const identifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
cell.textLabel.text = [myData objectAtIndex:indexPath.row];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary * dict =[NSDictionary dictionaryWithObject:@"Ravi" forKey:@"name"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"NOTIFICATION" object:nil userInfo:dict];
}
-(void) receivedNotification:(NSNotification*) notification {
NSLog(@"Notification Received ");
}
@end
in viewcontroller.h Datei
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UITableViewDelegate,UITableViewDataSource>
{
NSMutableArray *myData;
}
@property (weak, nonatomic) IBOutlet UITableView *mytableView;
@end