UITableViewCell中的ios滑块操作

时间:2016-04-10 19:49:37

标签: ios objective-c uitableview uislider

我在UITableViewCell错误中 -[MyCell slider:]: unrecognized selector sent to instance 0x7fcf81d82ab0 2016-04-10 22:24:49.947 TableViewController3[2372:153428] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MyCell slider:]: unrecognized selector sent to instance 0x7fcf81d82ab0'

this  my UITableViewCell

当我点击滑块时,它会显示:

#import <UIKit/UIKit.h>

    @interface MyCell : UITableViewCell


    @property (weak, nonatomic) IBOutlet UITextView *questionText;

    @property (weak, nonatomic) IBOutlet UITextField *slider_value_text;
    @property (weak, nonatomic) IBOutlet UISlider *slider;
    @end
-----------------------------------------------------------------------    


    #import "MyCell.h"

    @implementation MyCell

    - (void)awakeFromNib {
        [super awakeFromNib];
        // Initialization code
    }

    - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
        [super setSelected:selected animated:animated];

        // Configure the view for the selected state
    }

    @end

这是我的代码

我的TableViewCell类

#import <UIKit/UIKit.h>
#import "MyCell.h"
@interface myTableViewController : UITableViewController

@property NSArray *arr1;
-(void)Selector:(id)sender;
@end

我的UITableViewController类

  #import "myTableViewController.h"

@interface myTableViewController ()

@end

@implementation myTableViewController
@synthesize  arr1;

- (void)viewDidLoad {
    [super viewDidLoad];

    NSLog(@"here amq");
    arr1=@[@"homer",@"marge",@"lisa",@"asd eq hayde ewqewqsdaqww asd sad beklqwee awe qwe"];


}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Incomplete implementation, return the number of sections
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of rows
    return [arr1 count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    MyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];


    cell.questionText.text=[arr1 objectAtIndex:indexPath.row];
    [[cell slider ] setMaximumValue:1];
    [[cell slider ] setMaximumValue:5];
    [[cell slider ] setTintColor:[UIColor redColor]];
    [[cell slider] setTag:indexPath.row];
    [[cell slider] addTarget:self action:@selector(generalSelector:) forControlEvents:UIControlEventValueChanged];

    return cell;
}

-(void)Selector:(id)sender{
    if ([sender isKindOfClass:[UISlider class]]){
        UISlider *slider = (UISlider *)sender;
        NSLog(@"Slider value %f",slider.value);
    }

}
Program received signal SIGSEGV

1 个答案:

答案 0 :(得分:0)

当滑块更改其值时,您应该将generalSelector:替换为要调用的选择器的实际名称。 在这种情况下,您应该将generalSelector:替换为Selector: 如果您想要解释什么是选择器,请阅读此内容:https://developer.apple.com/library/ios/documentation/General/Conceptual/DevPedia-CocoaCore/Selector.html