开发者

iPhone - UITableViewCell having UIView which has 2 UIButton

I've a table view. In each cell (row), i want to show two buttons. initially both are red in color. when one button is clicked, it turns green and other will be in red. I created a view which has two buttons. I am using IB to create the view. i'm using following code to show the my table view to show the custom view:

- (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] autorelease];
    }

 NSArray *bundle = [[NSBundle mainBundle] loadNibNamed:@"CellView"
             owner:self options:nil];
 CellView *myView;
    for (id object in bundle) {
        if ([object isKindOfClass:[CellView class]])
            myView = (CellView *)object;
    }   
 NSString* str = [testArray objectAtIndex:indexPath.row];
 NSArray* arr = [str componentsSeparatedByString:@" "];
 myView.left.titleLabel.text = [arr objectAtIndex:0];
 myView.right.titleLabel.text = [arr objectAtI开发者_开发技巧ndex:1];

 [cell.contentView addSubview:myView];
    return cell;
}

Above code works fine but when the button is clicked, its showing the button with text that I created in IB. I am not understanding why is it happening?

Can some one guide me how to show a button in cell and handle its action?


I think you have to specify the titleLabel for different states of button. Then this code will work fine.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜