Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c IOS8 NSInvalidArgumentException无法识别的选择器已发送到实例_Objective C_Ios8 - Fatal编程技术网

Objective c IOS8 NSInvalidArgumentException无法识别的选择器已发送到实例

Objective c IOS8 NSInvalidArgumentException无法识别的选择器已发送到实例,objective-c,ios8,Objective C,Ios8,我的应用程序曾经在ios5到ios7上运行。最近我尝试用xcode6和simulator8在ios8上运行。应用程序崩溃了。当异常到达[[self-weightUnitsc_s]setSelectedSegmentIndex:0]时,我发现异常“NSInvalidArgumentException,reason-[UILabel selectedSegmentIndex]未识别的选择器发送到实例” - (UITableViewCell *)tableView:(UITableView *)tab

我的应用程序曾经在ios5到ios7上运行。最近我尝试用xcode6和simulator8在ios8上运行。应用程序崩溃了。当异常到达[[self-weightUnitsc_s]setSelectedSegmentIndex:0]时,我发现异常“NSInvalidArgumentException,reason-[UILabel selectedSegmentIndex]未识别的选择器发送到实例”

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
tableView.separatorColor=[UIColor colorWithRed:0 green:0.5765 blue:0.4431 alpha:1];

static NSString *CellIdentifier = @"Cell";

//UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];


if (indexPath.section==0){
    if (indexPath.row==0){
        weight * cell=(weight *)[tableView dequeueReusableCellWithIdentifier:@"weightcell"];
        if (cell == nil) {
            NSLog(@"weight nil");
            NSArray* arr=[[NSBundle mainBundle] loadNibNamed:@"weight" owner:self options:nil];
            cell= [arr objectAtIndex:0];
            [[cell weightUnitsc] setFrame:CGRectMake(cell.weightUnitsc.frame.origin.x, cell.weightUnitsc.frame.origin.y+5, cell.weightUnitsc.frame.size.width, 30)];
            [[cell weightUnitsc] addTarget:self action:@selector(segChange2) forControlEvents:UIControlEventValueChanged];

        }
        [cell LabelText:[Language get:@"setting.weightUnit" alter:@""]];
        [cell SegText:[Language get:@"setting.weightUnit.kg" alter:@""] :0];
        [cell SegText:[Language get:@"setting.weightUnit.g" alter:@""] :1];
        [cell SegText:[Language get:@"setting.weightUnit.lbs" alter:@""] :2];
        [cell SegText:[Language get:@"setting.weightUnit.oz" alter:@""] :3];


        [self setWeightUnitsc_s:[cell.contentView.subviews objectAtIndex:1]];
        switch ([WeightUnit getCurrentWeightID]) {
            case 1:
                [[self weightUnitsc_s] setSelectedSegmentIndex:1];
                break;
            case 2:
                [[self weightUnitsc_s] setSelectedSegmentIndex:2];
                break;
            case 3:
                [[self weightUnitsc_s] setSelectedSegmentIndex:3];
                break;
            default:
                [[self weightUnitsc_s] setSelectedSegmentIndex:0];
                break;
        }
        cell.selectionStyle=UITableViewCellSelectionStyleNone;

        [cell setBackgroundView:[[[UACellBackgroundView alloc] init] autorelease]];
        [(UACellBackgroundView *)[cell backgroundView] setPosition:UACellBackgroundViewPositionTop];

        return cell;
    }

有人能帮忙解释并解决这个问题吗?谢谢

您的代码假定
[cell.contentView.subviews objectAtIndex:1]
UISegmentedControl
,而实际上它是
UILabel
。这是依赖子视图索引而不是访问实际对象本身时发生的情况。当Apple以任何方式对视图层次结构进行更改时,您的代码就会被填充。在
weight
单元格中添加一个指向所需分段控件的属性(顺便说一句,名称很糟糕),然后通过该属性访问分段控件。我想我知道怎么修理它。