开发者

how to replace any view in UITableViewCell? (iphone)

I have made a tableView programatically.

in every cell I have made a button in that..

Now I want that when I press the button of first cell..that cellOne should be replaced by a new View.

can anyone tell me how to do that?

I开发者_如何学C mean when I press button of Cell no 1...only that particular cell should be replace by new view not other cell


add a flag in the datasource corresponding to each row (e.g in the array which you use to populate the table)...

in your cellForRowAtIndexPath method do conditional cell content population.. i.e. if the flag corresponding to that row is set, add the view else add the button...

when you press the button, set the flag corresponding to that row... and reload the table view...

its pretty straight forward..


You can set the contentView for that cell when the button in that corresponding cell is clicked.To make only tat cell is affected check the indexPath.row property value to be that corresponding row. For example:

if(indexPath.row==0)
{
[cell.contentView addSubView:yourView];
}

Hope this might help u Happy coding!


I am use reusable views inhered from UITableViewCell for any kind of cell in my TableView and dequeue cell view I need in dequeueReusableCellWithIdentifier. Then simple use reloadRowsAtIndexPaths:withRowAnimation: to replace view for cell. I am use IB to build view, but no problem to compose it (and register identifier if you want to reuse view) programmatically.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜