开发者

read text of selected cell

开发者 https://www.devze.com 2023-02-10 03:53 出处:网络
I have 2 columns in my table: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIn开发者_StackOverflowdexPath *)indexPath {

I have 2 columns in my table:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIn开发者_StackOverflowdexPath *)indexPath {  

    static NSUInteger const kLeftLabel =100;  
    static NSUInteger const kRightLabel=101;  

    static NSString *CellIdentifier = @"Cell";  


    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];  


    if (cell == nil) {  
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];  
        CGRect leftF = CGRectMake(10, 5, 100, 30);  
        CGRect rightF = CGRectMake(120, 5, 100, 30);  

    left = [[[UILabel alloc] initWithFrame:leftF] autorelease];  
    left.tag = kLeftLabel; // assumming #define kLeftLabel 100   
    [cell.contentView addSubview:left];  

  right = [[[UILabel alloc] initWithFrame:rightF] autorelease];  
    right.tag = kRightLabel;    

    [cell.contentView addSubview:right];  

    }  
    else{  
    left= (UILabel*)[cell.contentView viewWithTag:kLeftLabel];  
    right = (UILabel*)[cell.contentView viewWithTag:kRightLabel];  
    }  

    profileDB *Obj = [appDelegate.profileArray objectAtIndex:indexPath.row];  

    left.text = Obj.profileName;  
    right.text = Obj.id;  

    return cell;  
}

I want to read the right column's text only for a selected cell.

Is this possible?


First, You have to find out the selected cell.

 - (void) tableView:(UITableView*)tableview didSelectRowAtIndexPath:(NSIndexPath*)indexPath
 {
    UITableViewCell *cell = [tableview cellForRowAtIndexPath:indexPath];

    for(UILabel *lbl in [cell.contentView subviews])
    {
        if(([lbl isKindOfClass:[UILabel class]]) && ([lbl tag] == 101))
        {
            NSString *str = lbl.textLabel.text;

        }

    }
 }

If you have added subviews on cell, the you can specific label's text by using their tag

0

精彩评论

暂无评论...
验证码 换一张
取 消