Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a uitableViewCell by indexPath?

How can I get a UITableViewCell by indexPath? Like this:

I use the UIActionSheet, when I click confirm UIButton I want to change the cell text.

The nowIndex I define as a property

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {     if (buttonIndex == 0)     {         NSInteger section =  [nowIndex section];         NSInteger row = [nowIndex row];         NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];         formatter.dateFormat = @"yyyy-MM-dd";          if (section == 0)         {             if (row == 0)             {              }             else if (row == 1)             {                 UILabel *content = (UILabel *)[[(UITableView *)[actionSheet ] cellForRowAtIndexPath:nowIndex] viewWithTag:contentTag];                 content.text = [formatter stringFromDate:checkInDate.date];             }             else if (row == 2)             {              }         }     } } 
like image 683
phpxiaoxin Avatar asked Mar 05 '10 03:03

phpxiaoxin


People also ask

How do I get the IndexPath of a cell Swift?

add an 'indexPath` property to the custom table cell. initialize it in cellForRowAtIndexPath. move the tap handler from the view controller to the cell implementation. use the delegation pattern to notify the view controller about the tap event, passing the index path.

How do I get last IndexPath in Swift?

You can get the indexPath of the last row in last section like this. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:(numberOfRowsInLastSection - 1) inSection:(numberOfSections - 1)]; Here, numberOfSections is the value you return from numberOfSectionsInTableView: method.

What is IndexPath section in Swift?

Swift version: 5.6. Index paths describe an item's position inside a table view or collection view, storing both its section and its position inside that section.


2 Answers

[(UITableViewCell *)[(UITableView *)self cellForRowAtIndexPath:nowIndex] 

will give you uitableviewcell. But I am not sure what exactly you are asking for! Because you have this code and still you asking how to get uitableviewcell. Some more information will help to answer you :)

ADD: Here is an alternate syntax that achieves the same thing without the cast.

UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:nowIndex]; 
like image 138
Manjunath Avatar answered Oct 19 '22 07:10

Manjunath


Finally, I get the cell using the following code:

UITableViewCell *cell = (UITableViewCell *)[(UITableView *)self.view cellForRowAtIndexPath:nowIndex]; 

Because the class is extended UITableViewController:

@interface SearchHotelViewController : UITableViewController 

So, the self is "SearchHotelViewController".

like image 24
phpxiaoxin Avatar answered Oct 19 '22 08:10

phpxiaoxin