Best practice to pass a value from pop over control on iPad
It is an iPad app based on SDK 3.2.
I have a MainUIView, that is subclass from UIView, it have a UIButton and a UILabel. When user press the UIButton, the pop over control will be appeared with a table view. When the user select a cell from the table view, the UILabel changes content base on the user click, and the pop up table view will disappear.
The question is, how can I pass the "selected cell" to the UILabel. I am thinking making a "middle man" object. When the user click the UIButton, and the "middle man" will pass to the table. When the cell is selected, the "middle man" will store the idx, and call the UILabel change content from the value of "middle man".
开发者_开发技巧But I think it is pretty complex to implement, is there any easier way to implement it? thz u.
The standard way to do this is to call a delegate method when the popover closes with a selected value. The method will have been created on the view controller that calls the popover and handles setting the value.
In your view controller:
- (void) popoverDone:(id)sender {
label.text = [sender someValue];
[sender dismissPopoverAnimated:YES];
}
And in the popover:
- (void)tableView:tableView didSelectRowAtIndexPath:indexPath {
[delegate performSelector:@selector(popoverDone:) withObject:self];
}
There are other ways of doing this, but the principle is the same.
精彩评论