How can I get a uitableViewCell by indexPath?

phpxiaoxin picture phpxiaoxin · Mar 5, 2010 · Viewed 125.6k times · Source

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)
            {

            }
        }
    }
}

Answer

Manjunath picture Manjunath · Mar 5, 2010
[(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];