I have a simple custom table view cell that has a label and a textfield. Looks like this in the storyboard:
I would like to show the keyboard when the user clicks anywhere in the cell, including if they click the label. I was 99% sure the way to achieve this would be to call becomeFirstResponder when the cell is clicked.
Here is my simple ViewController:
#import "ViewController.h"
#interface ViewController ()
#property (weak, nonatomic) IBOutlet UITableView *tableView;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.dataSource = self;
self.tableView.delegate = self;
[self.tableView setEstimatedRowHeight:44.0f];
[self.tableView setRowHeight:UITableViewAutomaticDimension];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"custom"];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
BOOL firstResponder = [cell becomeFirstResponder];
}
And my custom table view cell:
#import "CustomTableViewCell.h"
#implementation CustomTableViewCell
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (BOOL) canBecomeFirstResponder {
return YES;
}
- (BOOL) becomeFirstResponder {
return [self.textField becomeFirstResponder];
}
#end
I verified that becomeFirstResponder is called, however that is returning false. What am I missing?
Think as #alex-i points out in a comment here:
This [text field not becoming first responder] can also occur when the textfield is briefly removed from the
view/window hierarchy while becoming the first responder (e.g.
reloading a UITableView or UICollectionView that holds that
textfield).
Which will happen on selection.
Rather than use didSelectRowAtIndexPath, you can add a UITapGestureRecognizer to your tableView with an action like:
- (IBAction)tap:(UITapGestureRecognizer *)sender
{
CGPoint location = [sender locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
BOOL firstResponder = [cell becomeFirstResponder];
}
And it will become first responder.
If someone needs a swift alternative: You can connect outer UIViews with outlet collection. On each UIViewController class you have once call below. So that when the outer box is touched, editfield will be activated with keyboard. You can apply this to your labels as well. (By disabling label's User Interaction)
#IBOutlet var outerBoxes:[UIView]!
override func viewDidLoad() {
super.viewDidLoad();
for outerBox in outerBoxes { outerBox.respondForEditBox() };
...
But once you have to have this code:
extension UIView {
func respondForEditBox() {
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIView.focusOnEditBox));
self.addGestureRecognizer(tap);
}
func focusOnEditBox() {
for sview in self.subviews {
if sview is UITextField {
sview.becomeFirstResponder();
}
}
}
}
Inspired by #Esqarrouth's answer at
Close iOS Keyboard by touching anywhere using Swift
Related
Hi I'm new to iOS Development and i am using Objective C. I have a problem in UITableview.That is, i need to write action for multiple UIButton which is loaded into a tableview(DutiesTableView.m & .h) as a custom cell(BreakTimeCell.m &.h). That tableview(DutiesTableView.m & .h) is loaded into another tableview(ViewController.m&.h, TableName is PersonalTable) as s custom cell using XIB.
[Shift(custom cell),Duties(UITableview),Break Time(UITableview)],[This is my ViewController.m
This is my sample output.When i click on the Break time UIButton it should show UIDatePicker on Main Tableview
Create A button,
UIButton *btnSample = [[UIButton alloc]initWithFrame:CGRectMake(215,10,100,50)];
[btnSample setTitle:#"Button Title" forState:UIControlStateNormal];
[yourView addSubview:btnSample];
Add a action to button
[btnSample addTarget:self action:#selector(your action or method) forControlEvents:UIControlEventTouchUpInside];
You can use delegates to get call back from custom cell to your view controller, for example in the custom cell in your code, BreakTimeCell.h file declare a protocol and add button in BreakTimeCell.xib and give outlet and action to custom cell like below,
#import <UIKit/UIKit.h>
#class BreakTimeCell; //forword declaration
#protocol BreakTimeCellDeleagte<NSObject>
- (void)breakTimeCell:(BreakTimeCell *)cell didTapTheButton:(UIButton *)aButton;
#end
#interface BreakTimeCell : UITableViewCell
#property (weak, nonatomic) IBOutlet UIButton *aButton;
#property (weak, nonatomic) id<BreakTimeCellDeleagte> cellDelegate;//this is important
- (IBAction)myButtonAction:(id)sender;
+ (BreakTimeCell *)getBreakTimeCell; //to get the custom cell
#end
and in BreakTimeCell.h file define action for the button
#import "BreakTimeCell.h"
#implementation BreakTimeCell
+ (BreakTimeCell *)getBreakTimeCell {
NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:#"BreakTimeCell" owner:self options:NULL];
NSEnumerator *nibEnumerator = [nibContents objectEnumerator];
BreakTimeCell *customCell = nil;
NSObject* nibItem = nil;
while ((nibItem = [nibEnumerator nextObject]) != nil) {
if ([nibItem isKindOfClass:[BreakTimeCell class]]) {
customCell = (BreakTimeCell *)nibItem;
break;
}
}
return customCell;
}
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
//call the delegate method in the button action
- (IBAction)myButtonAction:(id)sender {
if([self.cellDelegate respondsToSelector:#selector(breakTimeCell:didTapTheButton:)])
{
[self.cellDelegate breakTimeCell:self didTapTheButton:sender];
}
}
#end
and in view controller just set the cell delegate to view controller,
#import "ViewController.h"
#import "BreakTimeCell.h"
#interface ViewController ()<UITableViewDelegate, UITableViewDataSource, BreakTimeCellDeleagte>
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
BreakTimeCell *cell = [tableView dequeueReusableCellWithIdentifier:#"MY_BREAK_CELL"];
if (cell == nil) {
cell = [BreakTimeCell getBreakTimeCell]; //get the cell
}
cell.cellDelegate = self; //set the delegate to controller (self)
return cell;
}
//this is the delegate method called for the button action.
- (void)breakTimeCell:(BreakTimeCell *)cell didTapTheButton:(UIButton *)aButton {
NSIndexPath *indexPath = [self.personalTable indexPathForCell:cell];
NSLog(#"button tapped for index:%ld",(long)indexPath.row);
}
thats it, you will get output like below,
2017-12-13 11:44:24.693161+0530 Test[3082:100133] button tapped for index:3
2017-12-13 11:44:25.177169+0530 Test[3082:100133] button tapped for index:4
2017-12-13 11:44:26.223166+0530 Test[3082:100133] button tapped for index:0
2017-12-13 11:44:27.663060+0530 Test[3082:100133] button tapped for index:1
2017-12-13 11:44:28.495780+0530 Test[3082:100133] button tapped for index:2
Add this in cellForRow
yourButton.tag = indexPath.row;
[yourButton addTarget:self action:#selector(methodName:) forControlEvents:UIControlEventTouchUpInside];
Perform task in below method
- (void)methodName:(id)sender
{
// you can get index of button from sender.tag
}
i have two view controllers, view controller and tableViewController.
ViewController contains a textField and a button. when the button in viewController is clicked, then TableViewController should start.
in TableViewController, there is a list contains 5 rows, each row contains a string value.
What I am trying to do is, hen the user chooses any row in the list in TableViewController, then ViewController scene should start and the value that the user chose should be displayed in the textfield in ViewController.
to achieve this task, I created a protocol in TableViewController with a required method called valueChoosen: (NSString *) value, and this method is implemented in ViewController, and then I set the value to the textField but, at run time the TextField is empty.
please have look at the code below, and let me know why the value passed to the required method of the protocol can not be set to the textfield, what I am doing wrong;
TableViewController:
#import "TableViewController.h"
#interface TableViewController ()
#property NSArray *tableData;
#end
#implementation TableViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.tableData = [NSArray arrayWithObjects:#"Android",
#"iOS",
#"swift",
#"objective-c",
#"openCV",nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(NSInteger) tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
return [self.tableData count];
}
-(UITableViewCell *) tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simpleTableIdentifier = #"SimpleTableItem";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [self.tableData objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageNamed:#"images.jpg"];
return cell;
}
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:
(NSIndexPath *)indexPath {
NSLog(#"%#", [self.tableData objectAtIndex:indexPath.row]);
[self performSegueWithIdentifier:#"unwindSegue" sender:NULL];
[self.delegate valueChoosen:[self.tableData
objectAtIndex:indexPath.row]];
}
#end
ViewController:
#import "ViewController.h"
#import "TableViewController.h"
#interface ViewController ()
#property (strong, nonatomic) IBOutlet UITextField
*textFieldDepartment;
#property (strong, nonatomic) IBOutlet UIButton
*buttonSelectFromTableView;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a
nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"segueToTableView"]) {
//code
TableViewController *table = segue.destinationViewController;
table.delegate = self;
}
}
-(void) valueChoosen: (NSString *) value {
[_textFieldDepartment setText:value];
NSLog(#"value: %#", value);
}
#end
It maybe because you are setting the textfield text in the viewController which is not being displayed. Try assigning the value to a variable using the delegate function and call the delegate function before performing the unwind segue. And on the viewController try setting the textfield text as the variable whose value was set through delegate method from the viewWillAppear method.
Step 1:
create the unwind action in the viewcontroller you want to unwind it.in your case it is ViewController
- (IBAction)unwindFromModalController:(UIStoryboardSegue *)segue{}
Step 2:
Connect to the unwind Action
Control drag from tableviewcell to the Exit sign.
Select the Action you specified.
Add the Identifier to unwind segue.
Step3
Trigger the segue
in your TableViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
self.selectedText = self.tableData[indexPath.row];
[self performSegueWithIdentifier:#"unwindSegue" sender:self];}
Step 4:
Pass Data
Unwind Action
- (IBAction)unwindFromModalController:(UIStoryboardSegue *)segue{
if ([segue.sourceViewController isKindOfClass:[TableViewController class]]) {
TableViewController *vc = segue.sourceViewController;
if (vc.selectedText) {
[_textFieldDepartment setText:vc.selectedText];}
}
}
I'm trying to animate a few items in a custom UITableViewCell when a user presses a button in the cell. I have set addTarget: and added a method to animate the items in the cell. I've set a tag for the button so I can get the index. In the method, I call cellForRowAtIndexPath: to get the cell the button was called on. I'm casting the object returned by cellForRowAtIndexPath: to my custom cell. After I have the custom cell, I perform the animations on the objects. The problem is the animations aren't happening. When I try setting a property on one of the items in the cell, it doesn't work either. The custom cell is not returning nil so I'm not sure of the issue. What am I doing wrong?
Here is the code I'm using to call the animations
-(void)favButtonPressed:(id)sender{
FavoritesCell *favCell = (FavoritesCell *)[self tableView:self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:[sender tag] inSection:0]];
[UIView animateWithDuration:0.2 animations:^{
favCell.picButton.alpha = 0.5;
} completion:nil];
}
One way u can do it by using custom delegate like below, hope this helps u .
i took an example of your case go through this hope this helps u
in custom cell calss define delegate protocol like below
in FavoritesCell.h
#import <UIKit/UIKit.h>
#class FavoritesCell;
#protocol CellActionDelegate <NSObject>
- (void)doAnimationForCell:(FavoritesCell *)cell forButton:(UIButton *)picButton; //in this u can pass the cell itself
#end
#interface FavoritesCell : UITableViewCell
#property (nonatomic,retain)UIButton *picButton; //i am doing a simple test, say this is your pic button
#property (nonatomic,assign) id<CellActionDelegate>cellDelegate;
#end
and in FavoritesCell.m file
#import "FavoritesCell.h"
#implementation FavoritesCell
#synthesize cellDelegate;
#synthesize picButton = _picButton;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
_picButton = [[UIButton alloc]initWithFrame:CGRectMake(20, 3, 100, 100)];
//set the property // for test
[_picButton addTarget:self action:#selector(favButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[_picButton.layer setCornerRadius:50];
[_picButton.layer setMasksToBounds:YES];
[_picButton.layer setBorderColor:[[UIColor blackColor]CGColor]];
[_picButton.layer setBorderWidth:5];
_picButton.backgroundColor = [UIColor greenColor];
[self.contentView addSubview:_picButton];
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (void)favButtonPressed:(UIButton *)sender
{
//or you can do the animation hear only no need to delegate to controller form cell
if([self.cellDelegate respondsToSelector:#selector(doAnimationForCell:forButton:)])
{
[self.cellDelegate doAnimationForCell:self forButton:sender]; //call this method
}
}
#end
in ViewController.h file
#import <UIKit/UIKit.h>
#import "FavoritesCell.h" //import it
#interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate,CellActionDelegate> //confirms to delegate
//.... other stuffs
in ViewController.m file
//...other stuffs
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
FavoritesCell *cell = [tableView dequeueReusableCellWithIdentifier:#"CELL"];
if(cell == nil)
{
cell = [[FavoritesCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"CELL"];
}
cell.cellDelegate = self; //set the deleagte to this class
[cell.picButton setImage:[UIImage imageNamed:#"Two-Red-Flower-.jpg"] forState:UIControlStateNormal]; //set it hear or in custom cell itself
//...other logics
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 130.0f;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
//define the delegate method
- (void)doAnimationForCell:(FavoritesCell *)cell forButton:(UIButton *)picButton //this the picButton
{
//you can get index path of cell
//you can get the tapped button of the cell
//then do your animation
[UIView animateWithDuration:0.2 animations:^{
picButton.alpha = 0.5;
} completion:nil];
}
I think you want something like this:
-(void)favButtonPressed:(id)sender
{
CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:self.myTableView];
// or try this one alternatively if the above line give wrong indexPath
//CGPoint buttonPosition = [sender convertPoint:((UIButton *)sender).center toView:self.myTableView];
NSIndexPath *indexPath = [self.myTableView indexPathForRowAtPoint:buttonPosition];
// I assume "self" here is your view controller
FavoritesCell *favCell = (FavoritesCell *)[self.myTableView cellForRowAtIndexPath:indexPath];
[UIView animateWithDuration:0.2 animations:^{
favCell.picButton.alpha = 0.5;
} completion:nil];
}
I Have a button within a uitableview cell -
I have set it up to trigger a fmethod when clicked - (the function displays messages and resets the message count).
my code for this method is as follows -
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//Define Custom Cells
static NSString *CellCountI =#"CellCount";
UITableViewCell *cell;
feedData *f = [self.HpFeedArray objectAtIndex:indexPath.section];
//Comparison Strings
NSString *count = #"Count";
//If statement Cell Filters
//If Count Cell
if ([f.FeedGroup isEqualToString:count]) {
cell = [tableView dequeueReusableCellWithIdentifier:CellCountI forIndexPath:indexPath];
HP_Header_TableViewCell *hpTC = (HP_Header_TableViewCell *)cell;
hpTC.buttonPressedSelector = #selector(buttonImpMsg);
hpTC.buttonPressedTarget = self;
[hpTC.msgsBtn setTitle: f.FeedTitle forState: UIControlStateNormal];
return hpTC;
}
}
The buttonImpMsg method is as follows -
- (void)buttonImpMsg
{
NSLog(#"Back Button Pressed!");
[self removeBtn];
}
I would like to hide the button when clicked - but I'm not sure how to reference it from the buttonImpMsg method?
Pass the sender to the selector:-
- (void)buttonImpMsg:(id)sender {
[sender removeFromSuperview];
}
You could implement the delegate pattern, IMHO, it's the most proper way.
i think , better will be to make it hidden, if you want to again. – #pawan
I would also hide the button rather than remove it.
Try this implementation to hide the button, you can also do the same thing to hide this one after.
TableViewCell.h:
#import "TableViewCell.h"
#implementation TableViewCell
//.... Connect your action or set selector to this method:
- (IBAction)hideButton:(id)sender
{
UIButton *button = (UIButton *) sender;
// hide the button by using the setter
button.hidden = YES;
//.... Check if the delegate method has been implemented
if ([_delegate respondsToSelector:#selector(hideButton)]) {
[_delegate hideButton];
}
}
#end
TableViewCell.h
//... Declare the delegate:
#protocol CellDelegate <NSObject>
- (void)hideButton;
#end
#interface TableViewCell : UITableViewCell
//... Add a delegate property:
#property (strong, nonatomic) id <CellDelegate> delegate;
#end
ViewController.m:
//... set self a the delegate of your cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//...
cell.delete = self;
return cell;
}
ViewController.m:
//...
#interface ViewController () <CellDelegate>
//...
//... Implement the delegate method if you need to do stuff on the controller side
- (void)hideButton
{
//do stuff here if needed
}
I am trying to build a drop down menu. When I click a button button I want a table view to open and then tap on the UITableViewCell. I want the cell data to display in the button
.h file
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>{
IBOutlet UITableView *tblSimpleTable;
IBOutlet UIButton *btn;
IBOutlet UIImageView *i;
BOOL flag;
NSArray *arryData;
}
#property(nonatomic,retain)IBOutlet UITableView *tblSimpleTable;
#property(nonatomic,retain)IBOutlet UIButton *btn;
#property(nonatomic,retain)IBOutlet UIImageView *i;
-(IBAction)btnClicked;
#end
.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize btn;
#synthesize tblSimpleTable;
#synthesize i;
-(IBAction)btnClicked{
if (flag==1) {
flag=0;
tblSimpleTable.hidden=NO;
i.hidden=YES;
}
else{
flag=1;
tblSimpleTable.hidden=YES;
i.hidden=NO;
}
}
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
}
return self;
}
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
arryData = [[NSArray alloc] initWithObjects:#"iPhone",#"iPod",#"MacBook",#"MacBook Pro",nil];
//tblSimpleTable.frame =CGRectMake(10, 10, 300, 100);
flag=1;
tblSimpleTable.hidden=YES;
btn.layer.cornerRadius=8;
tblSimpleTable.layer.cornerRadius=8;
//i=[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"arrow-down.png"]];
[super viewDidLoad];
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}
#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [arryData count];
}
// Customize the appearance of table view cells.
- (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] ;
}
// Set up the cell...
cell.textLabel.text = [arryData objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
#end
You can do it in your didSelectRowAtIndexPath:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Changing button label
[_btn setTitle:[arryData objectAtIndex:indexPath.row] forState:UIControlStateNormal];
// Hiding table view
flag=1;
tblSimpleTable.hidden=YES;
i.hidden=NO;
}