开发者

Fetching value of label in custom cell

开发者 https://www.devze.com 2023-02-12 14:55 出处:网络
In custom cell I 开发者_StackOverflowhave a UILabel and UISwitch. I want to fetch the text of label when the switch is on. I have kept a method on switch\'s value changed event but the application is

In custom cell I 开发者_StackOverflowhave a UILabel and UISwitch. I want to fetch the text of label when the switch is on. I have kept a method on switch's value changed event but the application is getting crashed.


I'm assuming your mean a custom UITableViewCell. There are a number of ways of getting to the associated label when the switch changes:

  • If your table is not variable length (so that the cell with the label/switch is unique), when you create the cell cache the UILabel * object and the switch object in your UITableViewController subclass as ivars and associate them together.

  • If your table is variable length, you need to either maintain arrays of UILabel * and switch *, or you can also subclass UITableViewCell (note that you can provide a custom interface for a UITableViewCell via nib without having to necessarily subclass, you don't mention whether you've subclassed or not), hook up the switch event to go to your UITableViewCell subclass, then read the corresponding label, and/or forward the event to the UITableView subclass (this is a "push" model rather than the "pull" model), sometimes this organization is easier to manage than trying to maintain arrays of objects in your UITableViewCell that track objects in individual UITableViewCells.

0

精彩评论

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

关注公众号