UIsegmented 控件在集合视图中不起作用
UIsegmented control not working inside collection view
您好,我正在尝试为集合视图中的 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
}
}
以上代码不适用于 me.Any 帮助将不胜感激。
不是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
}
}
您好,我正在尝试为集合视图中的 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
}
}
以上代码不适用于 me.Any 帮助将不胜感激。
不是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
}
}