Hi I am new for ios and in my app I have created one NSModel Object for displaying tableList and when I tap on tableList row I want to take that model class object data to another class.
How can I do this?
Viewcontroller:-
NSMutableArray * mainArray;
//TableList Delegate Methods:-
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return mainArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"HistoryCell";
UITableViewCell *cell = (UITableViewCell *)[MaintableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
model1 = mainArray[indexPath.row];
cell.textLabel.text = model1.Name;
cell.detailTextLabel.text = model1.MasterId;
newBtn=[UIButton buttonWithType:UIButtonTypeCustom];
[newBtn setFrame:CGRectMake(250,5,30,30)];
[newBtn addTarget:self action:@selector(urSelctor:) forControlEvents:UIControlEventTouchUpInside];
UIImage *btnImage = [UIImage imageNamed:@"uncheck.png"];
[newBtn setImage:btnImage forState:UIControlStateNormal];
[cell addSubview:newBtn];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
ViewController1 *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController1"];
//ModelObject1 *model = mainArray[indexPath.row];
model1 = mainArray[indexPath.row];
controller.modelobj = model1;
controller.modelobjArray = mainArray;
[self.navigationController pushViewController:controller animated:YES];
}
-(void)urSelctor :(UIButton*)sender{
UIImage *currentImage = sender.imageView.image;
isValidate = [currentImage isEqual:[UIImage imageNamed:@"uncheck.png"]]?NO:YES;
NSLog(@"VALUE IS : %@", (isValidate) ? @"YES" : @"NO");
[sender setImage:[UIImage imageNamed:((isValidate) ? @"uncheck.png" : @"check.png")] forState:UIControlStateNormal];
if (isValidate) {
model1.ischeck = YES;
}else{
model1.ischeck = NO;
}
}
@end
Modelobject1:-
#import "ModelObject1.h"
@implementation ModelObject1
@synthesize MasterId,Name,ischeck;
-(void)loadingservices :(id)mainDictionary{
NSLog(@"loadingservices %@",mainDictionary);
Name = [mainDictionary objectForKey:@"Name"];
MasterId = [mainDictionary objectForKey:@"MasterId"];
}
@end
Viewcontroller1:-
#import "ViewController1.h"
@interface ViewController1 ()
@end
@implementation ViewController1
@synthesize modelobj,modelobjArray;
- (void)viewDidLoad {
[super viewDidLoad];
for (int i=0; i<modelobjArray.count;++i) {
modelobj = modelobjArray[i];
NSLog(@"Name is=======>%@",modelobj.Name);
NSLog(@"Check value is%hhd",modelobj.ischeck);
}
}