您好我正在尝试在集合视图中触发UIsegment控件的事件。
这是我的代码。
CollectionViewCell.h
@property (strong, nonatomic) IBOutlet UISegmentedControl *mySegmentedControl;
ViewController.m
{
NSInteger selectedSegment;
}
- (UIView *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
cell.mySegmentedControl.tag = indexPath.row;
selectedSegment = cell.mySegmentedControl.selectedSegmentIndex;
[cell.mySegmentedControl addTarget:self action:@selector(segmentValueChanged:) forControlEvents:UIControlEventValueChanged];
}
- (void) segmentValueChanged: (UISwitch *) sender {
//NSInteger index = sender.tag;
if(selectedSegment == 0)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"!Alert"
message:@"Do you think this property is not exists?"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Yes", nil];
[alert show];
}
else
{
//your code
}
}
以上代码对我不起作用。我们将不胜感激。
答案 0 :(得分:0)
UISwitch
不是UISegmentedControl
- (void) segmentValueChanged: (UISegmentedControl *) sender {
//NSInteger index = sender.tag;
if(sender.selectedSegmentIndex == 0)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"!Alert"
message:@"Do you think this property is not exists?"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Yes", nil];
[alert show];
}
else
{
//your code
}
}