I have 2 ViewControllers, in 1st - TableView and in 2nd - button with label on it. When I click on the button in 2nd ViewController I need to go back on TableView and set in
cell.detailTextLabel.text
text from label on the button.
Here is my code, but it does not work:
ViewController.h:
#import <UIKit/UIKit.h>
#import "TestControl.h"
#interface ViewController : UIViewController <UITableViewDataSource, UITableViewDelegate, myTestProtocol>
{
TestControl *myProtocol;
}
#property (strong, nonatomic) IBOutlet UITableView * tableTest;
#end
ViewController.m:
#import "ViewController.h"
#import "TestControl.h"
#implementation ViewController
#synthesize tableTest;
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.navigationBarHidden = YES;
myProtocol = [[TestControl alloc]init];
myProtocol.delegate = self;
// Do any additional setup after loading the view, typically from a nib.
}
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 3;
}
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
TestControl * test = [[TestControl alloc] initWithNibName:#"TestControl" bundle:nil];
[self.navigationController pushViewController:test animated:YES];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
switch (indexPath.row) {
case 0:
cell.textLabel.text = #"Firs Cell";
cell.detailTextLabel.text = myProtocol.myLabel.text;
break;
case 1:
cell.textLabel.text = #"Second Cell";
break;
case 2:
cell.textLabel.text = #"Third Cell";
break;
default:
break;
}
return cell;
}
#end
TestControl.h:
#import <UIKit/UIKit.h>
#protocol myTestProtocol <NSObject>
#end
#interface TestControl : UIViewController
{
UILabel *myLabel;
}
#property (nonatomic, assign) id <myTestProtocol> delegate;
#property (strong, nonatomic) IBOutlet UILabel *myLabel;
- (IBAction)testButton:(id)sender;
#end
TestControl.m:
#implementation TestControl
#synthesize myLabel;
#synthesize delegate;
- (IBAction)testButton:(id)sender
{
myLabel.text = #"TEXT LABEL";
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES];
}
What is the problem in this???
A couple of things....
You are creating two different TestControl objects, setting the delegate for one of them and pushing the other one, so the one handling the button tap has no delegate.
The delegate logic would work better the other way around. That is, TestControl should have the code that communicates with its delegate rather than the delegate "pulling" from TestControl.
Related
#import "MasterViewController.h"
#import "DetailViewController.h"
#interface MasterViewController ()
#end
#implementation MasterViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(#"Master", #"Master");
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
self.clearsSelectionOnViewWillAppear = NO;
self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0);
}
}
return self;
}
- (void)dealloc
{
[_detailViewController release];
[super dealloc];
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 5;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 100.0;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"CustomCell";
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier: CellIdentifier];
if (cell == nil)
{
cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.cellDate.text=#"date";
cell.cellDescription.text =#"Description";
cell.cellImageview.image = [UIImage imageNamed:#"facebook.png"];
cell.cellTitle.text = #"Title";
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
if (!self.detailViewController) {
self.detailViewController = [[[DetailViewController alloc] initWithNibName:#"DetailViewController_iPhone" bundle:nil] autorelease];
}
[self.navigationController pushViewController:self.detailViewController animated:YES];
}
else
{
}
}
#end
.h file
#import <UIKit/UIKit.h>
#import "CustomCell.h"
#import "XMLStringFile.h"
#class DetailViewController;
#interface MasterViewController : UITableViewController{
}
#property (strong, nonatomic) DetailViewController *detailViewController;
#property(strong,nonatomic)CustomCell *customCell;
#end
CustomCell.h
#import <UIKit/UIKit.h>
#interface CustomCell : UITableViewCell{
IBOutlet UIImageView *cellImageview;
IBOutlet UILabel *cellTitle;
IBOutlet UILabel *cellDescription;
IBOutlet UILabel *cellDate;
}
#property (retain, nonatomic) IBOutlet UIImageView *cellImageview;
#property (retain, nonatomic) IBOutlet UILabel *cellTitle;
#property (retain, nonatomic) IBOutlet UILabel *cellDescription;
#property (retain, nonatomic) IBOutlet UILabel *cellDate;
#end
CustomCell.m
#import "CustomCell.h"
#implementation CustomCell
#synthesize cellDate;
#synthesize cellDescription;
#synthesize cellImageview;
#synthesize cellTitle;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (void)dealloc {
[super dealloc];
}
#end
This is my both class
here Problem is in tableview data of the customcell cant Display onlt white screen.
Here i work in ios with masterdetails view template..
here i have also added m file in compile source
Customcell.xib size is 300X100
Here my output
My xib file as below
please help me to solve problem
if(cell == nil)
{
NSArray *outlets = [NSArray arrayWithArray:[[NSBundle mainBundle] loadNibNamed:#"CustomCell" owner:self options:nil]];
for(id obj in outlets)
{
if([obj isKindOfClass:[UITableViewCell class]])
{
cell = (CustomCell *)obj;
}
}
}
If your CustomCell is made via XIB then Write this Code where your cell is nil.
EDIT:-
This may be the cause - I think you haven't changed your CustomCell's class name. Follow these steps -
Take a XIB with name CustomCell.xib then delete its view.
Take a UITableViewCell and set its height and structure according to you.
Select File's Owner and change its class name to CustomCell, Same thing do with UITableViewCell... select it and change its class name to CustomCell.
Now connect all subView's IBOutLets.
Note:- Select IBOutLets by right clicking on UITableViewCell not from File's Owner.
Do the following in viewDidLoad
- (void)viewDidLoad
{
[super viewDidLoad];
UINib *nib = [UINib nibWithNibName:#"Customcell" bundle:nil];
[[self tableView] registerNib:nib forCellReuseIdentifier:#"CustomCell"];
}
If the cell is designed in a nib then you need to load the cell from the nib.
This actually has support in UIKit since iOS 5
What you need to do is register your nib with the UITableView.
- (void)viewDidLoad
{
[super viewDidLoad];
[self.tableView registerNib:[UINib nibWithNibName:#"Customcell" bundle:nil]
forCellReuseIdentifier:#"CustomCell"];
//...
}
Now your tableView:cellForRowAtIndexPath: just needs to look like this
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"CustomCell";
CustomCell *cell = (id)[tableView dequeueReusableCellWithIdentifier: CellIdentifier];
cell.cellDate.text = #"date";
cell.cellDescription.text = #"Description";
cell.cellImageview.image = [UIImage imageNamed:#"facebook.png"];
cell.cellTitle.text = #"Title";
return cell;
}
NB
Make sure to remember to set CustomCell as the reuseIdentifier in the xib
Some other observations
Really you should be using ARC for a new project.
#synthesize is implicit so not required in most cases
It's probably a bad idea to #import "CustomCell.h" in MasterViewController.h.
You should move this to the .m and use a forward declaration in the .h instead - #class CustomCell;
You also do not need to declare the backing ivars for properties as these will also be generated by the compiler e.g. you don't need to declare the following
#interface CustomCell : UITableViewCell {
IBOutlet UIImageView *cellImageview;
IBOutlet UILabel *cellTitle;
IBOutlet UILabel *cellDescription;
IBOutlet UILabel *cellDate;
}
I am trying to use ECSlidingViewController which is available on github:
https://github.com/edgecase/ECSlidingViewController
Anyway I was wondering how to push data from the menu view controller to the sample table view controller because there is no segue. The navigation controller gets instantiated via storybaord but I see no way to push any data from view to another.
I tried now with delegates but it seems my delegate does not fire for some reason I dont know. The TableView stays empty. What did I miss?
Please see code below:
//MenuviewController.h
#import <UIKit/UIKit.h>
#import "ECSlidingViewController.h"
#protocol TableData <NSObject>
- (void) someData:(NSString*)data;
#end
#interface MenuViewController : UIViewController <UITableViewDataSource, UITabBarControllerDelegate>{
__unsafe_unretained id <TableData> delegate;
}
#property (nonatomic,assign) id <TableData> delegate;
#end
//MenuViewController.m
#import "MenuViewController.h"
#interface MenuViewController()
#property (nonatomic, strong) NSArray *menuItems;
#end
#implementation MenuViewController
#synthesize menuItems, delegate;
- (void)awakeFromNib
{
self.menuItems = [NSArray arrayWithObjects:#"First", #"Second", #"Third", #"Navigation", nil];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self.slidingViewController setAnchorRightRevealAmount:280.0f];
self.slidingViewController.underLeftWidthLayout = ECFullWidth;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sectionIndex
{
return self.menuItems.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellIdentifier = #"MenuItemCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
cell.textLabel.text = [self.menuItems objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *identifier = [NSString stringWithFormat:#"%#Top", [self.menuItems objectAtIndex:indexPath.row]];
UIViewController *newTopViewController = [self.storyboard instantiateViewControllerWithIdentifier:identifier];
if ([delegate respondsToSelector:#selector(someData:)]) {
[delegate someData:#"Hello World"];
}
[self.slidingViewController anchorTopViewOffScreenTo:ECRight animations:nil onComplete:^{
CGRect frame = self.slidingViewController.topViewController.view.frame;
self.slidingViewController.topViewController = newTopViewController;
self.slidingViewController.topViewController.view.frame = frame;
[self.slidingViewController resetTopView];
}];
}
#end
//SampleTableViewController.h
#import <UIKit/UIKit.h>
#import "ECSlidingViewController.h"
#import "MenuViewController.h"
#interface SampleTableViewController : UITableViewController <UITableViewDataSource, UITabBarControllerDelegate, TableData>
- (IBAction)revealMenu:(id)sender;
#end
//SampleTableViewController.m
#import "SampleTableViewController.h"
#interface SampleTableViewController()
#property (nonatomic, strong) NSArray *sampleItems;
#end
#implementation SampleTableViewController
#synthesize sampleItems;
- (void)awakeFromNib
{
//self.sampleItems = [NSArray arrayWithObjects:#"One", #"Two", #"Three", nil];
}
- (void) someData:(NSString *)data{
sampleItems = [NSArray arrayWithContentsOfFile:data];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sectionIndex
{
return self.sampleItems.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellIdentifier = #"SampleCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
cell.textLabel.text = [self.sampleItems objectAtIndex:indexPath.row];
return cell;
}
- (IBAction)revealMenu:(id)sender
{
[self.slidingViewController anchorTopViewTo:ECRight];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return YES;
}
#end
I would suggest using a delegate. Here is an example: Delegate example
I finally found out.
Here is an example.
UINavigationController *navigationController = [self.storyboard instantiateViewControllerWithIdentifier:identifier];
MBFancyViewController *viewController = navigationController.viewControllers[0];
//or alternative
MBFancyViewController *viewController = (MBFancyViewController *)navigationController.topViewController;
// setup "inner" view controller
viewController.foo = bar;
[self presentViewController:navigationController animated:YES completion:nil];
Original question
I have a class named RootViewController and my .h file has the code below
#import "SEViewController.h"
#interface RootViewController : SEViewController{
}
#end
and my SEViewController looks like
#interface SEViewController : UIViewController
{
}
#end
How can i declare RootViewController as UITableViewController and also as SEViewController the same time?
Edited question
Now I have the code below, but I get warnings and the table view does not appear.
RootViewController.m:
#import <UIKit/UIKit.h>
#import "ApplicationCell.h"
#import "SEViewController.h"
#interface RootViewController : SEViewController <UITableViewDataSource, UITableViewDelegate>
{
UITableView *tableView;
ApplicationCell *tmpCell;
NSArray *data;
}
#property (copy) NSArray *data;
#property(nonatomic,retain)UITableView *tableView;
#end
RootViewController.m:
#import "RootViewController.h"
#import "SubviewApplicationCell.h"
#define DARK_BACKGROUND [UIColor viewFlipsideBackgroundColor]
#define LIGHT_BACKGROUND [UIColor clearColor];
#implementation RootViewController
#synthesize data;
#synthesize tableView = _tableView;
#pragma mark -
#pragma mark View controller methods
- (void)viewDidLoad
{
NSString *dataPath = [[NSBundle mainBundle] pathForResource:#"rules" ofType:#"plist"];
self.data = [NSArray arrayWithContentsOfFile:dataPath];
self.navigationItem.title = #"rules";
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
self.tableView = [[UITableView alloc]init];
self.tableView.rowHeight = 73.0;
self.tableView.backgroundColor = DARK_BACKGROUND;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[super viewDidLoad];
}
- (void)viewDidUnload
{
self.data = nil;
[super viewDidLoad];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return YES;
}
#pragma mark -
#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [data count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"ApplicationCell";
ApplicationCell *cell = (ApplicationCell *)[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[SubviewApplicationCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
}
cell.arrow = [UIImage imageNamed:#"circle"];
cell.name = [data objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.backgroundColor = LIGHT_BACKGROUND;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// [self.navigationController pushViewController:nil animated:YES];
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
#pragma mark -
#pragma mark Memory management
- (void)dealloc
{
[data release];
[super dealloc];
}
#end
Why dont you make
#interface SEViewController : UITableViewController
{
}
Or, create SEViewController as UIViewController, put a table on it, and implement the UITableViewDelegate, and you are going to have the same.
#interface SEViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
}
For creating and adding a table to your view, use this code:
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect totalFrame = self.view.frame;
UITableView *myTableView = [[UITableView alloc] initWithFrame:totalFrame style:UITableViewStylePlain];
[self.view addSubview:myTableView];
[myTableView release];
}
Objective C doesn't support multiple inheritance. So RootViewController can't be a subclass of both SEViewController and UITableViewController.
However, you can make RootViewController conform to the protocols : UITableViewDelegate and UITableViewDataSource, and implement the corresponding methods.
#interface RootViewController : SEViewController < UITableViewDelegate, UITableViewDataSource>
// tableView declaration;
#property (strong, nonatomic) UITableView *tableView;
// ...
#end
#implementation RootViewController
#synthesize tableView = _tableView;
// ...
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// ...
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
// ...
}
// ...
Edit After you showed your complete code, I think the problem is here:
#interface RootViewController : SEViewController <UITableViewDataSource, UITableViewDelegate>
{
UITableView *tableView; // Remove this line
ApplicationCell *tmpCell;
NSArray *data;
}
Multiple inheritance is not possible in objective-c ,all you can do is to incorporate table view in SEViewController and declare delegate methods in it.. hoping this helps....
You can only inherit from one parent class, but it sounds like you just want to do...
#interface RootViewController : SEViewController <UITableViewDataSource, UITableViewDelegate> {
I have two UITableView, each one has a different delegate in the same UIViewController.
I'm trying to call control in another delegate, but it failed.
Brief:
mainViewController contains UITableView (with UITableViewDelegate and UITableViewDataSource) + UIImageView.
secondaryTable contains UITableView (with UITableViewDelegate and UITableViewDataSource).
I want to call UIImageView from secondaryTable.
In .h
#interface secondaryTable : UIViewController <UITableViewDataSource,UITableViewDelegate>
#end
#interface mainViewController : UIViewController <UITableViewDataSource,UITableViewDelegate> {
#property (nonatomic,retain) IBOutlet UIImageView *navbar;
#property (nonatomic,retain) IBOutlet UITableView *Table1;
#property (nonatomic,retain) IBOutlet UITableView *Table2;
#end
In .m
#implementation secondaryTable
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 2;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = #"MyIdentifier2";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease];
[cell.textLabel setFont:[UIFont boldSystemFontOfSize:12.0]];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.textAlignment = UITextAlignmentCenter;
}
if (indexPath.row == 0) cell.textLabel.text =#"A";
if (indexPath.row == 1) cell.textLabel.text =#"B";
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(#"Selected");
mainViewController *myController = [[mainViewController alloc] init];
[myController.navbar setHidden:NO];
}
#end
#implementation mainViewController
- (void)viewDidLoad {
Table1.delegate = self;
Table1.dataSource = self;
secondaryTable *myDelegate = [secondaryTable alloc];
Table2.delegate = myDelegate;
Table2.dataSource = myDelegate;
#end
}
It types "Selected" in console log, but it won't show control.
Why can't it call navbar control in mainViewController?
I would suggest doing this by having both tables point to the same delegate but, within your delegate methods, select behaviour based on which table it is. Example:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (tableView == firstTable)
{
// Do appropriate things here
}
else if (tableView == secondTable)
{
// do things for table #2 here
}
else
{
assert(no); // error checking
}
}
I need to update image in Firstviewcontroller if cell is selected in tableviewcontroller.
My application Navigation base . Firstviewcontroller contains button event. tap on button i am firing tableview. In tableview i am selecting cell and updating checkmark in left side , It is working fine . My question is when cell is selected same time i need to update different custom image in viewcontroller for indicating cell is selected. With ref. i got image cell selecting in inside of tableview.
here it is Appdelegate
#interface FertilityAppAppDelegate : NSObject <UIApplicationDelegate>
{
Fertility *updateImage;
}
#property (nonatomic, retain) Fertility *updateImage;
#implementation
#synthesize updateImage;
#interface Fertility : UIViewController
{
UIImageView *imgView;
FertilityAppAppDelegate *Appdelegate;
}
#property(nonatomic,retain) FertilityAppAppDelegate *Appdelegate;
#property (nonatomic, retain) UIImageView *imgView;
Viewcontroller for image update
#implementation Fertility
#synthesize imgView,Appdelegate;
- (void)viewDidLoad
{
[super viewDidLoad];
Appdelegate = (FertilityAppAppDelegate*)[[UIApplication sharedApplication] delegate];
}
- (void)changeImg:(UIImage*)image
{
imgView.image = image;
}
- (void)assignObjToTableViewClass
{
Appdelegate.updateImage = self;
}
Tableview controller
#interface Menstruation : UITableViewController
{
FertilityAppAppDelegate *Appdelegate;
}
#property (nonatomic, retain) FertilityAppAppDelegate *Appdelegate;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIImage *image = [UIImage imageNamed:#"bar.png"];
[Appdelegate.updateImage changeImg:image];
selectedRow = indexPath.row;
[self.tableView reloadData];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
[[cell imageView] setImage:[UIImage imageNamed:#"Tick.png"]];
}
[[cell imageView] setHidden:YES];
if (indexPath.row == selectedRow)
{
[[cell imageView] setHidden:NO];
}
NSString *cellValue = [MenstruationArray objectAtIndex:indexPath.row];
cell.text = cellValue;
return cell;
}
How to display in Firstviewcontroller. the above image is Button with red color bar in bottom of button.
When i click this button in Firstviewcontroller firing for Menstruation table view, same time i need to update image bar to Firstviewcontroller.
if you want to change the image in the another view controller then you need to assign the image in the didSelectRowAtIndexPath method.
For that you need to access the specific view controller object(that is already using not the new one).
There are no tutorials, for these type of things.
I will send some code, please follow like that.
First of all you have to declare ImgViewController class object in the AppDelegateClass. Then only you can use.
Then use the following code. I have written this code for understanding.
#interface ImgViewController : UIViewController{
UIImageView *imgView;
AppDelegateClass *delegate;
}
#implementation ImgViewController
- (void)viewDidLoad{
delegate = (AppDelegateClass*)[[UIApplication sharedApplication]delegate];
delegate.imageViewControllerObj = self; // Or you can call the method
//[self assignObjToTableViewClass];
}
- (void)changeImg:(UIImage*)image{
imgView.image = image;
}
- (void)assignObjToTableViewClass{
delegate.imageViewControllerObj = self;
}
#end
#interface TableViewControllerClass : UIViewController{
AppDelegateClass *delegate;
}
#implementation TableViewControllerClass
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UIImage *image = //Give what ever image you want to change
[delegate.imageViewControllerObj changeImg:image];
}
#end
Regards,
Satya